home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / win32 / Winnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-08  |  174.9 KB  |  5,119 lines

  1. /*++ BUILD Version: 0093     Increment this if a change has global effects
  2.  
  3. Copyright (c) 1990-1996  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     winnt.h
  8.  
  9. Abstract:
  10.  
  11.     This module defines the 32-Bit Windows types and constants that are
  12.     defined by NT, but exposed through the Win32 API.
  13.  
  14. Revision History:
  15.  
  16. --*/
  17.  
  18. #ifndef _WINNT_
  19. #define _WINNT_
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. #include <ctype.h>  
  26. #define ANYSIZE_ARRAY 1       
  27.  
  28. #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
  29. #define RESTRICTED_POINTER __restrict
  30. #else
  31. #define RESTRICTED_POINTER
  32. #endif
  33.  
  34. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC)
  35. #define UNALIGNED __unaligned
  36. #else
  37. #define UNALIGNED
  38. #endif
  39.  
  40.  
  41. #if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
  42. #define DECLSPEC_IMPORT __declspec(dllimport)
  43. #else
  44. #define DECLSPEC_IMPORT
  45. #endif
  46.  
  47. typedef void *PVOID;    
  48.  
  49. #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
  50. #define NTAPI __stdcall
  51. #else
  52. #define _cdecl
  53. #define NTAPI
  54. #endif
  55.  
  56. //
  57. // Define API decoration for direct importing system DLL references.
  58. //
  59.  
  60. #if !defined(_NTSYSTEM_)
  61. #define NTSYSAPI DECLSPEC_IMPORT
  62. #else
  63. #define NTSYSAPI
  64. #endif
  65.  
  66.  
  67. //
  68. // Basics
  69. //
  70.  
  71. #ifndef VOID
  72. #define VOID void
  73. typedef char CHAR;
  74. typedef short SHORT;
  75. typedef long LONG;
  76. #endif
  77.  
  78. //
  79. // UNICODE (Wide Character) types
  80. //
  81.  
  82. typedef wchar_t WCHAR;    // wc,   16-bit UNICODE character
  83.  
  84. typedef WCHAR *PWCHAR;
  85. typedef WCHAR *LPWCH, *PWCH;
  86. typedef CONST WCHAR *LPCWCH, *PCWCH;
  87. typedef WCHAR *NWPSTR;
  88. typedef WCHAR *LPWSTR, *PWSTR;
  89.  
  90. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  91.  
  92. //
  93. // ANSI (Multi-byte Character) types
  94. //
  95. typedef CHAR *PCHAR;
  96. typedef CHAR *LPCH, *PCH;
  97.  
  98. typedef CONST CHAR *LPCCH, *PCCH;
  99. typedef CHAR *NPSTR;
  100. typedef CHAR *LPSTR, *PSTR;
  101. typedef CONST CHAR *LPCSTR, *PCSTR;
  102.  
  103. //
  104. // Neutral ANSI/UNICODE types and macros
  105. //
  106. #ifdef  UNICODE                     // r_winnt
  107.  
  108. #ifndef _TCHAR_DEFINED
  109. typedef WCHAR TCHAR, *PTCHAR;
  110. typedef WCHAR TBYTE , *PTBYTE ;
  111. #define _TCHAR_DEFINED
  112. #endif /* !_TCHAR_DEFINED */
  113.  
  114. typedef LPWSTR LPTCH, PTCH;
  115. typedef LPWSTR PTSTR, LPTSTR;
  116. typedef LPCWSTR LPCTSTR;
  117. typedef LPWSTR LP;
  118. #define __TEXT(quote) L##quote      // r_winnt
  119.  
  120. #else   /* UNICODE */               // r_winnt
  121.  
  122. #ifndef _TCHAR_DEFINED
  123. typedef char TCHAR, *PTCHAR;
  124. typedef unsigned char TBYTE , *PTBYTE ;
  125. #define _TCHAR_DEFINED
  126. #endif /* !_TCHAR_DEFINED */
  127.  
  128. typedef LPSTR LPTCH, PTCH;
  129. typedef LPSTR PTSTR, LPTSTR;
  130. typedef LPCSTR LPCTSTR;
  131. #define __TEXT(quote) quote         // r_winnt
  132.  
  133. #endif /* UNICODE */                // r_winnt
  134. #define TEXT(quote) __TEXT(quote)   // r_winnt
  135.  
  136.  
  137. typedef SHORT *PSHORT;  
  138. typedef LONG *PLONG;    
  139.  
  140. #ifdef STRICT
  141. typedef void *HANDLE;
  142. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  143. #else
  144. typedef PVOID HANDLE;
  145. #define DECLARE_HANDLE(name) typedef HANDLE name
  146. #endif
  147. typedef HANDLE *PHANDLE;
  148.  
  149. //
  150. // Flag (bit) fields
  151. //
  152.  
  153. typedef BYTE   FCHAR;
  154. typedef WORD   FSHORT;
  155. typedef DWORD  FLONG;
  156.  
  157. typedef char CCHAR;          
  158. typedef DWORD LCID;         
  159. typedef PDWORD PLCID;       
  160. typedef WORD   LANGID;      
  161. /*lint -e624 */  
  162. /*lint +e624 */  
  163. #define APPLICATION_ERROR_MASK       0x20000000
  164. #define ERROR_SEVERITY_SUCCESS       0x00000000
  165. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  166. #define ERROR_SEVERITY_WARNING       0x80000000
  167. #define ERROR_SEVERITY_ERROR         0xC0000000
  168.  
  169. //
  170. // __int64 is only supported by 2.0 and later midl.
  171. // __midl is set by the 2.0 midl and not by 1.0 midl.
  172. //
  173.  
  174. #define _DWORDLONG_
  175. #if (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))
  176. typedef __int64 LONGLONG;
  177. typedef unsigned __int64 DWORDLONG;
  178.  
  179. #define MAXLONGLONG                      (0x7fffffffffffffff)
  180. #else
  181. typedef double LONGLONG;
  182. typedef double DWORDLONG;
  183. #endif
  184.  
  185. typedef LONGLONG *PLONGLONG;
  186. typedef DWORDLONG *PDWORDLONG;
  187.  
  188. // Update Sequence Number
  189.  
  190. typedef LONGLONG USN;
  191.  
  192. #if defined(MIDL_PASS)
  193. typedef struct _LARGE_INTEGER {
  194. #else // MIDL_PASS
  195. typedef union _LARGE_INTEGER {
  196.     struct {
  197.         DWORD LowPart;
  198.         LONG HighPart;
  199.     };
  200.     struct {
  201.         DWORD LowPart;
  202.         LONG HighPart;
  203.     } u;
  204. #endif //MIDL_PASS
  205.     LONGLONG QuadPart;
  206. } LARGE_INTEGER;
  207.  
  208. typedef LARGE_INTEGER *PLARGE_INTEGER;
  209.  
  210.  
  211. #if defined(MIDL_PASS)
  212. typedef struct _ULARGE_INTEGER {
  213. #else // MIDL_PASS
  214. typedef union _ULARGE_INTEGER {
  215.     struct {
  216.         DWORD LowPart;
  217.         DWORD HighPart;
  218.     };
  219.     struct {
  220.         DWORD LowPart;
  221.         DWORD HighPart;
  222.     } u;
  223. #endif //MIDL_PASS
  224.     DWORDLONG QuadPart;
  225. } ULARGE_INTEGER;
  226.  
  227. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  228.  
  229. // end_ntminiport end_ntndis end_ntminitape
  230.  
  231. //
  232. // Locally Unique Identifier
  233. //
  234.  
  235. typedef struct _LUID {
  236.     DWORD LowPart;
  237.     LONG HighPart;
  238. } LUID, *PLUID;
  239.  
  240.  
  241. //
  242. // Define operations to logically shift an int64 by 0..31 bits and to multiply
  243. // 32-bits by 32-bits to form a 64-bit product.
  244. //
  245.  
  246. #if defined(MIDL_PASS) || defined(RC_INVOKED)
  247.  
  248. //
  249. // Midl does not understand inline assembler. Therefore, the Rtl functions
  250. // are used for shifts by 0.31 and multiplies of 32-bits times 32-bits to
  251. // form a 64-bit product.
  252. //
  253.  
  254. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  255. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  256.  
  257. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  258. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  259. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  260.  
  261. #elif defined(_M_MRX000)
  262.  
  263. //
  264. // MIPS uses intrinsic functions to perform shifts by 0..31 and multiplies of
  265. // 32-bits times 32-bits to 64-bits.
  266. //
  267.  
  268. #define Int32x32To64 __emul
  269. #define UInt32x32To64 __emulu
  270.  
  271. #define Int64ShllMod32 __ll_lshift
  272. #define Int64ShraMod32 __ll_rshift
  273. #define Int64ShrlMod32 __ull_rshift
  274.  
  275. #if defined (__cplusplus)
  276. extern "C" {
  277. #endif
  278.  
  279. LONGLONG
  280. NTAPI
  281. Int32x32To64 (
  282.     LONG Multiplier,
  283.     LONG Multiplicand
  284.     );
  285.  
  286. DWORDLONG
  287. NTAPI
  288. UInt32x32To64 (
  289.     DWORD Multiplier,
  290.     DWORD Multiplicand
  291.     );
  292.  
  293. DWORDLONG
  294. NTAPI
  295. Int64ShllMod32 (
  296.     DWORDLONG Value,
  297.     DWORD ShiftCount
  298.     );
  299.  
  300. LONGLONG
  301. NTAPI
  302. Int64ShraMod32 (
  303.     LONGLONG Value,
  304.     DWORD ShiftCount
  305.     );
  306.  
  307. DWORDLONG
  308. NTAPI
  309. Int64ShrlMod32 (
  310.     DWORDLONG Value,
  311.     DWORD ShiftCount
  312.     );
  313.  
  314. #if defined (__cplusplus)
  315. };
  316. #endif
  317.  
  318. #pragma intrinsic(__emul)
  319. #pragma intrinsic(__emulu)
  320.  
  321. #pragma intrinsic(__ll_lshift)
  322. #pragma intrinsic(__ll_rshift)
  323. #pragma intrinsic(__ull_rshift)
  324.  
  325. #elif defined(_M_IX86)
  326.  
  327. //
  328. // The x86 C compiler understands inline assembler. Therefore, inline functions
  329. // that employ inline assembler are used for shifts of 0..31.  The multiplies
  330. // rely on the compiler recognizing the cast of the multiplicand to int64 to
  331. // generate the optimal code inline.
  332. //
  333.  
  334. #define Int32x32To64( a, b ) (LONGLONG)((LONGLONG)(LONG)(a) * (LONG)(b))
  335. #define UInt32x32To64( a, b ) (DWORDLONG)((DWORDLONG)(DWORD)(a) * (DWORD)(b))
  336.  
  337. DWORDLONG
  338. NTAPI
  339. Int64ShllMod32 (
  340.     DWORDLONG Value,
  341.     DWORD ShiftCount
  342.     );
  343.  
  344. LONGLONG
  345. NTAPI
  346. Int64ShraMod32 (
  347.     LONGLONG Value,
  348.     DWORD ShiftCount
  349.     );
  350.  
  351. DWORDLONG
  352. NTAPI
  353. Int64ShrlMod32 (
  354.     DWORDLONG Value,
  355.     DWORD ShiftCount
  356.     );
  357.  
  358. #pragma warning(disable:4035)               // re-enable below
  359.  
  360. __inline DWORDLONG
  361. NTAPI
  362. Int64ShllMod32 (
  363.     DWORDLONG Value,
  364.     DWORD ShiftCount
  365.     )
  366. {
  367.     __asm    {
  368.         mov     ecx, ShiftCount
  369.         mov     eax, dword ptr [Value]
  370.         mov     edx, dword ptr [Value+4]
  371.         shld    edx, eax, cl
  372.         shl     eax, cl
  373.     }
  374. }
  375.  
  376. __inline LONGLONG
  377. NTAPI
  378. Int64ShraMod32 (
  379.     LONGLONG Value,
  380.     DWORD ShiftCount
  381.     )
  382. {
  383.     __asm {
  384.         mov     ecx, ShiftCount
  385.         mov     eax, dword ptr [Value]
  386.         mov     edx, dword ptr [Value+4]
  387.         shrd    eax, edx, cl
  388.         sar     edx, cl
  389.     }
  390. }
  391.  
  392. __inline DWORDLONG
  393. NTAPI
  394. Int64ShrlMod32 (
  395.     DWORDLONG Value,
  396.     DWORD ShiftCount
  397.     )
  398. {
  399.     __asm    {
  400.         mov     ecx, ShiftCount
  401.         mov     eax, dword ptr [Value]
  402.         mov     edx, dword ptr [Value+4]
  403.         shrd    eax, edx, cl
  404.         shr     edx, cl
  405.     }
  406. }
  407.  
  408. #pragma warning(default:4035)
  409.  
  410. #elif defined(_M_ALPHA)
  411.  
  412. //
  413. // Alpha has native 64-bit operations that are just as fast as their 32-bit
  414. // counter parts. Therefore, the int64 data type is used directly to form
  415. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  416. // product.
  417. //
  418.  
  419. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  420. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  421.  
  422. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  423. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  424. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  425.  
  426.  
  427. #elif defined(_M_PPC)
  428.  
  429. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  430. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  431.  
  432. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  433. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  434. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  435.  
  436. #else
  437.  
  438. #error Must define a target architecture.
  439.  
  440. #endif
  441.  
  442. #define UNICODE_NULL ((WCHAR)0) 
  443. typedef BYTE  BOOLEAN;           
  444. typedef BOOLEAN *PBOOLEAN;       
  445. //
  446. //  Doubly linked list structure.  Can be used as either a list head, or
  447. //  as link words.
  448. //
  449.  
  450. typedef struct _LIST_ENTRY {
  451.    struct _LIST_ENTRY * volatile Flink;
  452.    struct _LIST_ENTRY * volatile Blink;
  453. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  454.  
  455. //
  456. //  Singly linked list structure. Can be used as either a list head, or
  457. //  as link words.
  458. //
  459.  
  460. typedef struct _SINGLE_LIST_ENTRY {
  461.     struct _SINGLE_LIST_ENTRY *Next;
  462. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  463.  
  464. //
  465. // Base data structures for OLE support
  466. //
  467.  
  468. #ifndef GUID_DEFINED
  469. #define GUID_DEFINED
  470.  
  471. typedef struct _GUID {          // size is 16
  472.     DWORD Data1;
  473.     WORD   Data2;
  474.     WORD   Data3;
  475.     BYTE  Data4[8];
  476. } GUID;
  477.  
  478. #endif // !GUID_DEFINED
  479.  
  480. #ifndef __OBJECTID_DEFINED
  481. #define __OBJECTID_DEFINED
  482.  
  483. typedef struct  _OBJECTID {     // size is 20
  484.     GUID Lineage;
  485.     DWORD Uniquifier;
  486. } OBJECTID;
  487. #endif // !_OBJECTID_DEFINED
  488.  
  489. #define MINCHAR     0x80        
  490. #define MAXCHAR     0x7f        
  491. #define MINSHORT    0x8000      
  492. #define MAXSHORT    0x7fff      
  493. #define MINLONG     0x80000000  
  494. #define MAXLONG     0x7fffffff  
  495. #define MAXBYTE     0xff        
  496. #define MAXWORD     0xffff      
  497. #define MAXDWORD    0xffffffff  
  498. //
  499. // Calculate the byte offset of a field in a structure of type type.
  500. //
  501.  
  502. #define FIELD_OFFSET(type, field)    ((LONG)&(((type *)0)->field))
  503.  
  504.  
  505. //
  506. // Calculate the address of the base of the structure given its type, and an
  507. // address of a field within the structure.
  508. //
  509.  
  510. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  511.                                                   (PCHAR)(address) - \
  512.                                                   (PCHAR)(&((type *)0)->field)))
  513.  
  514. //
  515. //  Language IDs.
  516. //
  517. //  The following two combinations of primary language ID and
  518. //  sublanguage ID have special semantics:
  519. //
  520. //    Primary Language ID   Sublanguage ID      Result
  521. //    -------------------   ---------------     ------------------------
  522. //    LANG_NEUTRAL          SUBLANG_NEUTRAL     Language neutral
  523. //    LANG_NEUTRAL          SUBLANG_DEFAULT     User default language
  524. //    LANG_NEUTRAL          SUBLANG_SYS_DEFAULT System default language
  525. //
  526.  
  527. //
  528. //  Primary language IDs.
  529. //
  530.  
  531. #define LANG_NEUTRAL                     0x00
  532.  
  533. #define LANG_AFRIKAANS                   0x36
  534. #define LANG_ALBANIAN                    0x1c
  535. #define LANG_ARABIC                      0x01
  536. #define LANG_BASQUE                      0x2d
  537. #define LANG_BELARUSIAN                  0x23
  538. #define LANG_BULGARIAN                   0x02
  539. #define LANG_CATALAN                     0x03
  540. #define LANG_CHINESE                     0x04
  541. #define LANG_CROATIAN                    0x1a
  542. #define LANG_CZECH                       0x05
  543. #define LANG_DANISH                      0x06
  544. #define LANG_DUTCH                       0x13
  545. #define LANG_ENGLISH                     0x09
  546. #define LANG_ESTONIAN                    0x25
  547. #define LANG_FAEROESE                    0x38
  548. #define LANG_FARSI                       0x29
  549. #define LANG_FINNISH                     0x0b
  550. #define LANG_FRENCH                      0x0c
  551. #define LANG_GERMAN                      0x07
  552. #define LANG_GREEK                       0x08
  553. #define LANG_HEBREW                      0x0d
  554. #define LANG_HUNGARIAN                   0x0e
  555. #define LANG_ICELANDIC                   0x0f
  556. #define LANG_INDONESIAN                  0x21
  557. #define LANG_ITALIAN                     0x10
  558. #define LANG_JAPANESE                    0x11
  559. #define LANG_KOREAN                      0x12
  560. #define LANG_LATVIAN                     0x26
  561. #define LANG_LITHUANIAN                  0x27
  562. #define LANG_NORWEGIAN                   0x14
  563. #define LANG_POLISH                      0x15
  564. #define LANG_PORTUGUESE                  0x16
  565. #define LANG_ROMANIAN                    0x18
  566. #define LANG_RUSSIAN                     0x19
  567. #define LANG_SERBIAN                     0x1a
  568. #define LANG_SLOVAK                      0x1b
  569. #define LANG_SLOVENIAN                   0x24
  570. #define LANG_SPANISH                     0x0a
  571. #define LANG_SWEDISH                     0x1d
  572. #define LANG_THAI                        0x1e
  573. #define LANG_TURKISH                     0x1f
  574. #define LANG_UKRAINIAN                   0x22
  575. #define LANG_VIETNAMESE                  0x2a
  576.  
  577. //
  578. //  Sublanguage IDs.
  579. //
  580. //  The name immediately following SUBLANG_ dictates which primary
  581. //  language ID that sublanguage ID can be combined with to form a
  582. //  valid language ID.
  583. //
  584.  
  585. #define SUBLANG_NEUTRAL                  0x00    // language neutral
  586. #define SUBLANG_DEFAULT                  0x01    // user default
  587. #define SUBLANG_SYS_DEFAULT              0x02    // system default
  588.  
  589. #define SUBLANG_ARABIC_SAUDI_ARABIA      0x01    // Arabic (Saudi Arabia)
  590. #define SUBLANG_ARABIC_IRAQ              0x02    // Arabic (Iraq)
  591. #define SUBLANG_ARABIC_EGYPT             0x03    // Arabic (Egypt)
  592. #define SUBLANG_ARABIC_LIBYA             0x04    // Arabic (Libya)
  593. #define SUBLANG_ARABIC_ALGERIA           0x05    // Arabic (Algeria)
  594. #define SUBLANG_ARABIC_MOROCCO           0x06    // Arabic (Morocco)
  595. #define SUBLANG_ARABIC_TUNISIA           0x07    // Arabic (Tunisia)
  596. #define SUBLANG_ARABIC_OMAN              0x08    // Arabic (Oman)
  597. #define SUBLANG_ARABIC_YEMEN             0x09    // Arabic (Yemen)
  598. #define SUBLANG_ARABIC_SYRIA             0x0a    // Arabic (Syria)
  599. #define SUBLANG_ARABIC_JORDAN            0x0b    // Arabic (Jordan)
  600. #define SUBLANG_ARABIC_LEBANON           0x0c    // Arabic (Lebanon)
  601. #define SUBLANG_ARABIC_KUWAIT            0x0d    // Arabic (Kuwait)
  602. #define SUBLANG_ARABIC_UAE               0x0e    // Arabic (U.A.E)
  603. #define SUBLANG_ARABIC_BAHRAIN           0x0f    // Arabic (Bahrain)
  604. #define SUBLANG_ARABIC_QATAR             0x10    // Arabic (Qatar)
  605. #define SUBLANG_CHINESE_TRADITIONAL      0x01    // Chinese (Taiwan)
  606. #define SUBLANG_CHINESE_SIMPLIFIED       0x02    // Chinese (PR China)
  607. #define SUBLANG_CHINESE_HONGKONG         0x03    // Chinese (Hong Kong)
  608. #define SUBLANG_CHINESE_SINGAPORE        0x04    // Chinese (Singapore)
  609. #define SUBLANG_DUTCH                    0x01    // Dutch
  610. #define SUBLANG_DUTCH_BELGIAN            0x02    // Dutch (Belgian)
  611. #define SUBLANG_ENGLISH_US               0x01    // English (USA)
  612. #define SUBLANG_ENGLISH_UK               0x02    // English (UK)
  613. #define SUBLANG_ENGLISH_AUS              0x03    // English (Australian)
  614. #define SUBLANG_ENGLISH_CAN              0x04    // English (Canadian)
  615. #define SUBLANG_ENGLISH_NZ               0x05    // English (New Zealand)
  616. #define SUBLANG_ENGLISH_EIRE             0x06    // English (Irish)
  617. #define SUBLANG_ENGLISH_SOUTH_AFRICA     0x07    // English (South Africa)
  618. #define SUBLANG_ENGLISH_JAMAICA          0x08    // English (Jamaica)
  619. #define SUBLANG_ENGLISH_CARIBBEAN        0x09    // English (Caribbean)
  620. #define SUBLANG_ENGLISH_BELIZE           0x0a    // English (Belize)
  621. #define SUBLANG_ENGLISH_TRINIDAD         0x0b    // English (Trinidad)
  622. #define SUBLANG_FRENCH                   0x01    // French
  623. #define SUBLANG_FRENCH_BELGIAN           0x02    // French (Belgian)
  624. #define SUBLANG_FRENCH_CANADIAN          0x03    // French (Canadian)
  625. #define SUBLANG_FRENCH_SWISS             0x04    // French (Swiss)
  626. #define SUBLANG_FRENCH_LUXEMBOURG        0x05    // French (Luxembourg)
  627. #define SUBLANG_GERMAN                   0x01    // German
  628. #define SUBLANG_GERMAN_SWISS             0x02    // German (Swiss)
  629. #define SUBLANG_GERMAN_AUSTRIAN          0x03    // German (Austrian)
  630. #define SUBLANG_GERMAN_LUXEMBOURG        0x04    // German (Luxembourg)
  631. #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05    // German (Liechtenstein)
  632. #define SUBLANG_ITALIAN                  0x01    // Italian
  633. #define SUBLANG_ITALIAN_SWISS            0x02    // Italian (Swiss)
  634. #define SUBLANG_KOREAN                   0x01    // Korean (Extended Wansung)
  635. #define SUBLANG_KOREAN_JOHAB             0x02    // Korean (Johab)
  636. #define SUBLANG_NORWEGIAN_BOKMAL         0x01    // Norwegian (Bokmal)
  637. #define SUBLANG_NORWEGIAN_NYNORSK        0x02    // Norwegian (Nynorsk)
  638. #define SUBLANG_PORTUGUESE               0x02    // Portuguese
  639. #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01    // Portuguese (Brazilian)
  640. #define SUBLANG_SERBIAN_LATIN            0x02    // Serbian (Latin)
  641. #define SUBLANG_SERBIAN_CYRILLIC         0x03    // Serbian (Cyrillic)
  642. #define SUBLANG_SPANISH                  0x01    // Spanish (Castilian)
  643. #define SUBLANG_SPANISH_MEXICAN          0x02    // Spanish (Mexican)
  644. #define SUBLANG_SPANISH_MODERN           0x03    // Spanish (Modern)
  645. #define SUBLANG_SPANISH_GUATEMALA        0x04    // Spanish (Guatemala)
  646. #define SUBLANG_SPANISH_COSTA_RICA       0x05    // Spanish (Costa Rica)
  647. #define SUBLANG_SPANISH_PANAMA           0x06    // Spanish (Panama)
  648. #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07  // Spanish (Dominican Republic)
  649. #define SUBLANG_SPANISH_VENEZUELA        0x08    // Spanish (Venezuela)
  650. #define SUBLANG_SPANISH_COLOMBIA         0x09    // Spanish (Colombia)
  651. #define SUBLANG_SPANISH_PERU             0x0a    // Spanish (Peru)
  652. #define SUBLANG_SPANISH_ARGENTINA        0x0b    // Spanish (Argentina)
  653. #define SUBLANG_SPANISH_ECUADOR          0x0c    // Spanish (Ecuador)
  654. #define SUBLANG_SPANISH_CHILE            0x0d    // Spanish (Chile)
  655. #define SUBLANG_SPANISH_URUGUAY          0x0e    // Spanish (Uruguay)
  656. #define SUBLANG_SPANISH_PARAGUAY         0x0f    // Spanish (Paraguay)
  657. #define SUBLANG_SPANISH_BOLIVIA          0x10    // Spanish (Bolivia)
  658. #define SUBLANG_SPANISH_EL_SALVADOR      0x11    // Spanish (El Salvador)
  659. #define SUBLANG_SPANISH_HONDURAS         0x12    // Spanish (Honduras)
  660. #define SUBLANG_SPANISH_NICARAGUA        0x13    // Spanish (Nicaragua)
  661. #define SUBLANG_SPANISH_PUERTO_RICO      0x14    // Spanish (Puerto Rico)
  662. #define SUBLANG_SWEDISH                  0x01    // Swedish
  663. #define SUBLANG_SWEDISH_FINLAND          0x02    // Swedish (Finland)
  664.  
  665. //
  666. //  Sorting IDs.
  667. //
  668.  
  669. #define SORT_DEFAULT                     0x0     // sorting default
  670.  
  671. #define SORT_JAPANESE_XJIS               0x0     // Japanese XJIS order
  672. #define SORT_JAPANESE_UNICODE            0x1     // Japanese Unicode order
  673.  
  674. #define SORT_CHINESE_BIG5                0x0     // Chinese BIG5 order
  675. #define SORT_CHINESE_PRCP                0x0     // PRC Chinese Phonetic order
  676. #define SORT_CHINESE_UNICODE             0x1     // Chinese Unicode order
  677. #define SORT_CHINESE_PRC                 0x2     // PRC Chinese Stroke Count order
  678.  
  679. #define SORT_KOREAN_KSC                  0x0     // Korean KSC order
  680. #define SORT_KOREAN_UNICODE              0x1     // Korean Unicode order
  681.  
  682. #define SORT_GERMAN_PHONE_BOOK           0x1     // German Phone Book order
  683.  
  684. // end_r_winnt
  685.  
  686. //
  687. //  A language ID is a 16 bit value which is the combination of a
  688. //  primary language ID and a secondary language ID.  The bits are
  689. //  allocated as follows:
  690. //
  691. //       +-----------------------+-------------------------+
  692. //       |     Sublanguage ID    |   Primary Language ID   |
  693. //       +-----------------------+-------------------------+
  694. //        15                   10 9                       0   bit
  695. //
  696. //
  697. //  Language ID creation/extraction macros:
  698. //
  699. //    MAKELANGID    - construct language id from a primary language id and
  700. //                    a sublanguage id.
  701. //    PRIMARYLANGID - extract primary language id from a language id.
  702. //    SUBLANGID     - extract sublanguage id from a language id.
  703. //
  704.  
  705. #define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
  706. #define PRIMARYLANGID(lgid)    ((WORD  )(lgid) & 0x3ff)
  707. #define SUBLANGID(lgid)        ((WORD  )(lgid) >> 10)
  708.  
  709.  
  710. //
  711. //  A locale ID is a 32 bit value which is the combination of a
  712. //  language ID, a sort ID, and a reserved area.  The bits are
  713. //  allocated as follows:
  714. //
  715. //       +-------------+---------+-------------------------+
  716. //       |   Reserved  | Sort ID |      Language ID        |
  717. //       +-------------+---------+-------------------------+
  718. //        31         20 19     16 15                      0   bit
  719. //
  720. //
  721. //  Locale ID creation/extraction macros:
  722. //
  723. //    MAKELCID       - construct locale id from a language id and a sort id.
  724. //    LANGIDFROMLCID - extract language id from a locale id.
  725. //    SORTIDFROMLCID - extract sort id from a locale id.
  726. //
  727.  
  728. #define NLS_VALID_LOCALE_MASK  0x000fffff
  729.  
  730. #define MAKELCID(lgid, srtid)  ((DWORD)((((DWORD)((WORD  )(srtid))) << 16) |  \
  731.                                          ((DWORD)((WORD  )(lgid)))))
  732. #define LANGIDFROMLCID(lcid)   ((WORD  )(lcid))
  733. #define SORTIDFROMLCID(lcid)   ((WORD  )((((DWORD)(lcid)) & NLS_VALID_LOCALE_MASK) >> 16))
  734.  
  735.  
  736. //
  737. //  Default System and User IDs for language and locale.
  738. //
  739.  
  740. #define LANG_SYSTEM_DEFAULT    (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  741. #define LANG_USER_DEFAULT      (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  742.  
  743. #define LOCALE_SYSTEM_DEFAULT  (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  744. #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  745.  
  746. #define LOCALE_NEUTRAL                                                        \
  747.           (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
  748.  
  749.  
  750. // begin_ntminiport begin_ntndis begin_ntminitape
  751.  
  752. //
  753. // Macros used to eliminate compiler warning generated when formal
  754. // parameters or local variables are not declared.
  755. //
  756. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  757. // referenced but will be once the module is completely developed.
  758. //
  759. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  760. // referenced but will be once the module is completely developed.
  761. //
  762. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  763. //
  764. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  765. // eventually be made into a null macro to help determine whether there
  766. // is unfinished work.
  767. //
  768.  
  769. #if ! (defined(lint) || defined(_lint))
  770. #define UNREFERENCED_PARAMETER(P)          (P)
  771. #define DBG_UNREFERENCED_PARAMETER(P)      (P)
  772. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  773.  
  774. #else // lint or _lint
  775.  
  776. // Note: lint -e530 says don't complain about uninitialized variables for
  777. // this.  line +e530 turns that checking back on.  Error 527 has to do with
  778. // unreachable code.
  779.  
  780. #define UNREFERENCED_PARAMETER(P)          \
  781.     /*lint -e527 -e530 */ \
  782.     { \
  783.         (P) = (P); \
  784.     } \
  785.     /*lint +e527 +e530 */
  786. #define DBG_UNREFERENCED_PARAMETER(P)      \
  787.     /*lint -e527 -e530 */ \
  788.     { \
  789.         (P) = (P); \
  790.     } \
  791.     /*lint +e527 +e530 */
  792. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \
  793.     /*lint -e527 -e530 */ \
  794.     { \
  795.         (V) = (V); \
  796.     } \
  797.     /*lint +e527 +e530 */
  798.  
  799. #endif // lint or _lint
  800.  
  801.  
  802. #ifndef WIN32_NO_STATUS 
  803. /*lint -save -e767 */  
  804. #define STATUS_WAIT_0                    ((DWORD   )0x00000000L)    
  805. #define STATUS_ABANDONED_WAIT_0          ((DWORD   )0x00000080L)    
  806. #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)    
  807. #define STATUS_TIMEOUT                   ((DWORD   )0x00000102L)    
  808. #define STATUS_PENDING                   ((DWORD   )0x00000103L)    
  809. #define STATUS_SEGMENT_NOTIFICATION      ((DWORD   )0x40000005L)    
  810. #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD   )0x80000001L)    
  811. #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)    
  812. #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)    
  813. #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)    
  814. #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)    
  815. #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)    
  816. #define STATUS_INVALID_HANDLE            ((DWORD   )0xC0000008L)    
  817. #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)    
  818. #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)    
  819. #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)    
  820. #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)    
  821. #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)    
  822. #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)    
  823. #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)    
  824. #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)    
  825. #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)    
  826. #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)    
  827. #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)    
  828. #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)    
  829. #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)    
  830. #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)    
  831. #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)    
  832. #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)    
  833. #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)    
  834. /*lint -restore */  
  835. #endif 
  836. #define MAXIMUM_WAIT_OBJECTS 64     // Maximum number of wait objects
  837.  
  838. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  839. typedef DWORD KSPIN_LOCK;  
  840.  
  841. #ifdef _ALPHA_                          // winnt
  842. void *_rdteb(void);                     // winnt
  843. #if defined(_M_ALPHA)                   // winnt
  844. #pragma intrinsic(_rdteb)               // winnt
  845. #endif                                  // winnt
  846. #endif                                  // winnt
  847.  
  848. #if defined(_M_ALPHA)
  849. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  850. #else
  851. struct _TEB *
  852. NtCurrentTeb(void);
  853. #endif
  854.  
  855. //
  856. // Define function to return the current Thread Environment Block
  857. //
  858.  
  859. #ifdef _ALPHA_
  860.  
  861.  
  862.  
  863. //
  864. // Define functions to get the address of the current fiber and the
  865. // current fiber data.
  866. //
  867.  
  868. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  869. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  870.  
  871. // begin_ntddk begin_nthal
  872. //
  873. // The following flags control the contents of the CONTEXT structure.
  874. //
  875.  
  876. #if !defined(RC_INVOKED)
  877.  
  878. #define CONTEXT_PORTABLE_32BIT     0x00100000
  879. #define CONTEXT_ALPHA              0x00020000
  880.  
  881. #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
  882. #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
  883. #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
  884.  
  885. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  886.  
  887. #endif
  888.  
  889. #ifndef _PORTABLE_32BIT_CONTEXT
  890.  
  891. //
  892. // Context Frame
  893. //
  894. //  This frame has a several purposes: 1) it is used as an argument to
  895. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  896. //  3) it is used to construct a call frame for exception dispatching
  897. //  in user mode, 4) it is used in the user level thread creation
  898. //  routines, and 5) it is used to to pass thread state to debuggers.
  899. //
  900. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  901. //  a multiple of 16 bytes in length.
  902. //
  903. //  There are two variations of the context structure. This is the real one.
  904. //
  905.  
  906. typedef struct _CONTEXT {
  907.  
  908.     //
  909.     // This section is specified/returned if the ContextFlags word contains
  910.     // the flag CONTEXT_FLOATING_POINT.
  911.     //
  912.  
  913.     DWORDLONG FltF0;
  914.     DWORDLONG FltF1;
  915.     DWORDLONG FltF2;
  916.     DWORDLONG FltF3;
  917.     DWORDLONG FltF4;
  918.     DWORDLONG FltF5;
  919.     DWORDLONG FltF6;
  920.     DWORDLONG FltF7;
  921.     DWORDLONG FltF8;
  922.     DWORDLONG FltF9;
  923.     DWORDLONG FltF10;
  924.     DWORDLONG FltF11;
  925.     DWORDLONG FltF12;
  926.     DWORDLONG FltF13;
  927.     DWORDLONG FltF14;
  928.     DWORDLONG FltF15;
  929.     DWORDLONG FltF16;
  930.     DWORDLONG FltF17;
  931.     DWORDLONG FltF18;
  932.     DWORDLONG FltF19;
  933.     DWORDLONG FltF20;
  934.     DWORDLONG FltF21;
  935.     DWORDLONG FltF22;
  936.     DWORDLONG FltF23;
  937.     DWORDLONG FltF24;
  938.     DWORDLONG FltF25;
  939.     DWORDLONG FltF26;
  940.     DWORDLONG FltF27;
  941.     DWORDLONG FltF28;
  942.     DWORDLONG FltF29;
  943.     DWORDLONG FltF30;
  944.     DWORDLONG FltF31;
  945.  
  946.     //
  947.     // This section is specified/returned if the ContextFlags word contains
  948.     // the flag CONTEXT_INTEGER.
  949.     //
  950.     // N.B. The registers gp, sp, and ra are defined in this section, but are
  951.     //  considered part of the control context rather than part of the integer
  952.     //  context.
  953.     //
  954.  
  955.     DWORDLONG IntV0;    //  $0: return value register, v0
  956.     DWORDLONG IntT0;    //  $1: temporary registers, t0 - t7
  957.     DWORDLONG IntT1;    //  $2:
  958.     DWORDLONG IntT2;    //  $3:
  959.     DWORDLONG IntT3;    //  $4:
  960.     DWORDLONG IntT4;    //  $5:
  961.     DWORDLONG IntT5;    //  $6:
  962.     DWORDLONG IntT6;    //  $7:
  963.     DWORDLONG IntT7;    //  $8:
  964.     DWORDLONG IntS0;    //  $9: nonvolatile registers, s0 - s5
  965.     DWORDLONG IntS1;    // $10:
  966.     DWORDLONG IntS2;    // $11:
  967.     DWORDLONG IntS3;    // $12:
  968.     DWORDLONG IntS4;    // $13:
  969.     DWORDLONG IntS5;    // $14:
  970.     DWORDLONG IntFp;    // $15: frame pointer register, fp/s6
  971.     DWORDLONG IntA0;    // $16: argument registers, a0 - a5
  972.     DWORDLONG IntA1;    // $17:
  973.     DWORDLONG IntA2;    // $18:
  974.     DWORDLONG IntA3;    // $19:
  975.     DWORDLONG IntA4;    // $20:
  976.     DWORDLONG IntA5;    // $21:
  977.     DWORDLONG IntT8;    // $22: temporary registers, t8 - t11
  978.     DWORDLONG IntT9;    // $23:
  979.     DWORDLONG IntT10;   // $24:
  980.     DWORDLONG IntT11;   // $25:
  981.     DWORDLONG IntRa;    // $26: return address register, ra
  982.     DWORDLONG IntT12;   // $27: temporary register, t12
  983.     DWORDLONG IntAt;    // $28: assembler temp register, at
  984.     DWORDLONG IntGp;    // $29: global pointer register, gp
  985.     DWORDLONG IntSp;    // $30: stack pointer register, sp
  986.     DWORDLONG IntZero;  // $31: zero register, zero
  987.  
  988.     //
  989.     // This section is specified/returned if the ContextFlags word contains
  990.     // the flag CONTEXT_FLOATING_POINT.
  991.     //
  992.  
  993.     DWORDLONG Fpcr;     // floating point control register
  994.     DWORDLONG SoftFpcr; // software extension to FPCR
  995.  
  996.     //
  997.     // This section is specified/returned if the ContextFlags word contains
  998.     // the flag CONTEXT_CONTROL.
  999.     //
  1000.     // N.B. The registers gp, sp, and ra are defined in the integer section,
  1001.     //   but are considered part of the control context rather than part of
  1002.     //   the integer context.
  1003.     //
  1004.  
  1005.     DWORDLONG Fir;      // (fault instruction) continuation address
  1006.     DWORD Psr;          // processor status
  1007.  
  1008.     //
  1009.     // The flags values within this flag control the contents of
  1010.     // a CONTEXT record.
  1011.     //
  1012.     // If the context record is used as an input parameter, then
  1013.     // for each portion of the context record controlled by a flag
  1014.     // whose value is set, it is assumed that that portion of the
  1015.     // context record contains valid context. If the context record
  1016.     // is being used to modify a thread's context, then only that
  1017.     // portion of the threads context will be modified.
  1018.     //
  1019.     // If the context record is used as an IN OUT parameter to capture
  1020.     // the context of a thread, then only those portions of the thread's
  1021.     // context corresponding to set flags will be returned.
  1022.     //
  1023.     // The context record is never used as an OUT only parameter.
  1024.     //
  1025.  
  1026.     DWORD ContextFlags;
  1027.     DWORD Fill[4];      // padding for 16-byte stack frame alignment
  1028.  
  1029. } CONTEXT, *PCONTEXT;
  1030.  
  1031. #else
  1032.  
  1033. //
  1034. // 32-bit Context Frame
  1035. //
  1036. //  This alternate version of the Alpha context structure parallels that
  1037. //  of MIPS and IX86 in style for the first 64 entries: 32-bit machines
  1038. //  can operate on the fields, and a value declared as a pointer to an
  1039. //  array of int's can be used to index into the fields.  This makes life
  1040. //  with windbg and ntsd vastly easier.
  1041. //
  1042. //  There are two parts: the first contains the lower 32-bits of each
  1043. //  element in the 64-bit definition above.  The second part contains
  1044. //  the upper 32-bits of each 64-bit element above.
  1045. //
  1046. //  The names in the first part are identical to the 64-bit names.
  1047. //  The second part names are prefixed with "High".
  1048. //
  1049. //  1st half: at 32 bits each, (containing the low parts of 64-bit values)
  1050. //      32 floats, 32 ints, fpcrs, fir, psr, contextflags
  1051. //  2nd half: at 32 bits each
  1052. //      32 floats, 32 ints, fpcrs, fir, fill
  1053. //
  1054. //  There is no external support for the 32-bit version of the context
  1055. //  structure.  It is only used internally by windbg and ntsd.
  1056. //
  1057. //  This structure must be the same size as the 64-bit version above.
  1058. //
  1059.  
  1060. typedef struct _CONTEXT {
  1061.  
  1062.     DWORD FltF0;
  1063.     DWORD FltF1;
  1064.     DWORD FltF2;
  1065.     DWORD FltF3;
  1066.     DWORD FltF4;
  1067.     DWORD FltF5;
  1068.     DWORD FltF6;
  1069.     DWORD FltF7;
  1070.     DWORD FltF8;
  1071.     DWORD FltF9;
  1072.     DWORD FltF10;
  1073.     DWORD FltF11;
  1074.     DWORD FltF12;
  1075.     DWORD FltF13;
  1076.     DWORD FltF14;
  1077.     DWORD FltF15;
  1078.     DWORD FltF16;
  1079.     DWORD FltF17;
  1080.     DWORD FltF18;
  1081.     DWORD FltF19;
  1082.     DWORD FltF20;
  1083.     DWORD FltF21;
  1084.     DWORD FltF22;
  1085.     DWORD FltF23;
  1086.     DWORD FltF24;
  1087.     DWORD FltF25;
  1088.     DWORD FltF26;
  1089.     DWORD FltF27;
  1090.     DWORD FltF28;
  1091.     DWORD FltF29;
  1092.     DWORD FltF30;
  1093.     DWORD FltF31;
  1094.  
  1095.     DWORD IntV0;        //  $0: return value register, v0
  1096.     DWORD IntT0;        //  $1: temporary registers, t0 - t7
  1097.     DWORD IntT1;        //  $2:
  1098.     DWORD IntT2;        //  $3:
  1099.     DWORD IntT3;        //  $4:
  1100.     DWORD IntT4;        //  $5:
  1101.     DWORD IntT5;        //  $6:
  1102.     DWORD IntT6;        //  $7:
  1103.     DWORD IntT7;        //  $8:
  1104.     DWORD IntS0;        //  $9: nonvolatile registers, s0 - s5
  1105.     DWORD IntS1;        // $10:
  1106.     DWORD IntS2;        // $11:
  1107.     DWORD IntS3;        // $12:
  1108.     DWORD IntS4;        // $13:
  1109.     DWORD IntS5;        // $14:
  1110.     DWORD IntFp;        // $15: frame pointer register, fp/s6
  1111.     DWORD IntA0;        // $16: argument registers, a0 - a5
  1112.     DWORD IntA1;        // $17:
  1113.     DWORD IntA2;        // $18:
  1114.     DWORD IntA3;        // $19:
  1115.     DWORD IntA4;        // $20:
  1116.     DWORD IntA5;        // $21:
  1117.     DWORD IntT8;        // $22: temporary registers, t8 - t11
  1118.     DWORD IntT9;        // $23:
  1119.     DWORD IntT10;       // $24:
  1120.     DWORD IntT11;       // $25:
  1121.     DWORD IntRa;        // $26: return address register, ra
  1122.     DWORD IntT12;       // $27: temporary register, t12
  1123.     DWORD IntAt;        // $28: assembler temp register, at
  1124.     DWORD IntGp;        // $29: global pointer register, gp
  1125.     DWORD IntSp;        // $30: stack pointer register, sp
  1126.     DWORD IntZero;      // $31: zero register, zero
  1127.  
  1128.     DWORD Fpcr;         // floating point control register
  1129.     DWORD SoftFpcr;     // software extension to FPCR
  1130.  
  1131.     DWORD Fir;          // (fault instruction) continuation address
  1132.  
  1133.     DWORD Psr;          // processor status
  1134.     DWORD ContextFlags;
  1135.  
  1136.     //
  1137.     // Beginning of the "second half".
  1138.     // The name "High" parallels the HighPart of a LargeInteger.
  1139.     //
  1140.  
  1141.     DWORD HighFltF0;
  1142.     DWORD HighFltF1;
  1143.     DWORD HighFltF2;
  1144.     DWORD HighFltF3;
  1145.     DWORD HighFltF4;
  1146.     DWORD HighFltF5;
  1147.     DWORD HighFltF6;
  1148.     DWORD HighFltF7;
  1149.     DWORD HighFltF8;
  1150.     DWORD HighFltF9;
  1151.     DWORD HighFltF10;
  1152.     DWORD HighFltF11;
  1153.     DWORD HighFltF12;
  1154.     DWORD HighFltF13;
  1155.     DWORD HighFltF14;
  1156.     DWORD HighFltF15;
  1157.     DWORD HighFltF16;
  1158.     DWORD HighFltF17;
  1159.     DWORD HighFltF18;
  1160.     DWORD HighFltF19;
  1161.     DWORD HighFltF20;
  1162.     DWORD HighFltF21;
  1163.     DWORD HighFltF22;
  1164.     DWORD HighFltF23;
  1165.     DWORD HighFltF24;
  1166.     DWORD HighFltF25;
  1167.     DWORD HighFltF26;
  1168.     DWORD HighFltF27;
  1169.     DWORD HighFltF28;
  1170.     DWORD HighFltF29;
  1171.     DWORD HighFltF30;
  1172.     DWORD HighFltF31;
  1173.  
  1174.     DWORD HighIntV0;        //  $0: return value register, v0
  1175.     DWORD HighIntT0;        //  $1: temporary registers, t0 - t7
  1176.     DWORD HighIntT1;        //  $2:
  1177.     DWORD HighIntT2;        //  $3:
  1178.     DWORD HighIntT3;        //  $4:
  1179.     DWORD HighIntT4;        //  $5:
  1180.     DWORD HighIntT5;        //  $6:
  1181.     DWORD HighIntT6;        //  $7:
  1182.     DWORD HighIntT7;        //  $8:
  1183.     DWORD HighIntS0;        //  $9: nonvolatile registers, s0 - s5
  1184.     DWORD HighIntS1;        // $10:
  1185.     DWORD HighIntS2;        // $11:
  1186.     DWORD HighIntS3;        // $12:
  1187.     DWORD HighIntS4;        // $13:
  1188.     DWORD HighIntS5;        // $14:
  1189.     DWORD HighIntFp;        // $15: frame pointer register, fp/s6
  1190.     DWORD HighIntA0;        // $16: argument registers, a0 - a5
  1191.     DWORD HighIntA1;        // $17:
  1192.     DWORD HighIntA2;        // $18:
  1193.     DWORD HighIntA3;        // $19:
  1194.     DWORD HighIntA4;        // $20:
  1195.     DWORD HighIntA5;        // $21:
  1196.     DWORD HighIntT8;        // $22: temporary registers, t8 - t11
  1197.     DWORD HighIntT9;        // $23:
  1198.     DWORD HighIntT10;       // $24:
  1199.     DWORD HighIntT11;       // $25:
  1200.     DWORD HighIntRa;        // $26: return address register, ra
  1201.     DWORD HighIntT12;       // $27: temporary register, t12
  1202.     DWORD HighIntAt;        // $28: assembler temp register, at
  1203.     DWORD HighIntGp;        // $29: global pointer register, gp
  1204.     DWORD HighIntSp;        // $30: stack pointer register, sp
  1205.     DWORD HighIntZero;      // $31: zero register, zero
  1206.  
  1207.     DWORD HighFpcr;         // floating point control register
  1208.     DWORD HighSoftFpcr;     // software extension to FPCR
  1209.     DWORD HighFir;          // processor status
  1210.  
  1211.     double DoNotUseThisField; // to force quadword structure alignment
  1212.     DWORD HighFill[2];      // padding for 16-byte stack frame alignment
  1213.  
  1214. } CONTEXT, *PCONTEXT;
  1215.  
  1216. //
  1217. // These should name the fields in the _PORTABLE_32BIT structure
  1218. // that overlay the Psr and ContextFlags in the normal structure.
  1219. //
  1220.  
  1221. #define _QUAD_PSR_OFFSET   HighSoftFpcr
  1222. #define _QUAD_FLAGS_OFFSET HighFir
  1223.  
  1224. #endif // _PORTABLE_32BIT_CONTEXT
  1225.  
  1226. // end_ntddk end_nthal
  1227.  
  1228. #endif // _ALPHA_
  1229.  
  1230.  
  1231. #ifdef _ALPHA_
  1232.  
  1233. VOID
  1234. __jump_unwind (
  1235.     PVOID VirtualFramePointer,
  1236.     PVOID TargetPc
  1237.     );
  1238.  
  1239. #endif // _ALPHA_
  1240.  
  1241.  
  1242. #ifdef _X86_
  1243.  
  1244. //
  1245. // Disable these two pramas that evaluate to "sti" "cli" on x86 so that driver
  1246. // writers to not leave them inadvertantly in their code.
  1247. //
  1248.  
  1249. #if !defined(MIDL_PASS)
  1250. #if !defined(RC_INVOKED)
  1251.  
  1252. #pragma warning(disable:4164)   // disable C4164 warning so that apps that
  1253.                                 // build with /Od don't get weird errors !
  1254. #ifdef _M_IX86
  1255. #pragma function(_enable)
  1256. #pragma function(_disable)
  1257. #endif
  1258.  
  1259. #pragma warning(default:4164)   // reenable C4164 warning
  1260.  
  1261. #endif
  1262. #endif
  1263.  
  1264.  
  1265. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1266. #pragma warning (disable:4035)        // disable 4035 (function must return something)
  1267. _inline PVOID GetFiberData( void ) { __asm {
  1268.                                         mov eax, fs:[0x10]
  1269.                                         mov eax,[eax]
  1270.                                         }
  1271.                                      }
  1272. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  1273.  
  1274. #pragma warning (default:4035)        // Reenable it
  1275. #endif
  1276.  
  1277. // begin_wx86
  1278.  
  1279. //
  1280. //  Define the size of the 80387 save area, which is in the context frame.
  1281. //
  1282.  
  1283. #define SIZE_OF_80387_REGISTERS      80
  1284.  
  1285. //
  1286. // The following flags control the contents of the CONTEXT structure.
  1287. //
  1288.  
  1289. #if !defined(RC_INVOKED)
  1290.  
  1291. #define CONTEXT_i386    0x00010000    // this assumes that i386 and
  1292. #define CONTEXT_i486    0x00010000    // i486 have identical context records
  1293.  
  1294. // end_wx86
  1295.  
  1296. #define CONTEXT_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1297. #define CONTEXT_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1298. #define CONTEXT_SEGMENTS        (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1299. #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
  1300. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1301.  
  1302. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1303.                       CONTEXT_SEGMENTS)
  1304.  
  1305. // begin_wx86
  1306.  
  1307. #endif
  1308.  
  1309. typedef struct _FLOATING_SAVE_AREA {
  1310.     DWORD   ControlWord;
  1311.     DWORD   StatusWord;
  1312.     DWORD   TagWord;
  1313.     DWORD   ErrorOffset;
  1314.     DWORD   ErrorSelector;
  1315.     DWORD   DataOffset;
  1316.     DWORD   DataSelector;
  1317.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  1318.     DWORD   Cr0NpxState;
  1319. } FLOATING_SAVE_AREA;
  1320.  
  1321. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1322.  
  1323. //
  1324. // Context Frame
  1325. //
  1326. //  This frame has a several purposes: 1) it is used as an argument to
  1327. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1328. //  and 3) it is used in the user level thread creation routines.
  1329. //
  1330. //  The layout of the record conforms to a standard call frame.
  1331. //
  1332.  
  1333. typedef struct _CONTEXT {
  1334.  
  1335.     //
  1336.     // The flags values within this flag control the contents of
  1337.     // a CONTEXT record.
  1338.     //
  1339.     // If the context record is used as an input parameter, then
  1340.     // for each portion of the context record controlled by a flag
  1341.     // whose value is set, it is assumed that that portion of the
  1342.     // context record contains valid context. If the context record
  1343.     // is being used to modify a threads context, then only that
  1344.     // portion of the threads context will be modified.
  1345.     //
  1346.     // If the context record is used as an IN OUT parameter to capture
  1347.     // the context of a thread, then only those portions of the thread's
  1348.     // context corresponding to set flags will be returned.
  1349.     //
  1350.     // The context record is never used as an OUT only parameter.
  1351.     //
  1352.  
  1353.     DWORD ContextFlags;
  1354.  
  1355.     //
  1356.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1357.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1358.     // included in CONTEXT_FULL.
  1359.     //
  1360.  
  1361.     DWORD   Dr0;
  1362.     DWORD   Dr1;
  1363.     DWORD   Dr2;
  1364.     DWORD   Dr3;
  1365.     DWORD   Dr6;
  1366.     DWORD   Dr7;
  1367.  
  1368.     //
  1369.     // This section is specified/returned if the
  1370.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1371.     //
  1372.  
  1373.     FLOATING_SAVE_AREA FloatSave;
  1374.  
  1375.     //
  1376.     // This section is specified/returned if the
  1377.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1378.     //
  1379.  
  1380.     DWORD   SegGs;
  1381.     DWORD   SegFs;
  1382.     DWORD   SegEs;
  1383.     DWORD   SegDs;
  1384.  
  1385.     //
  1386.     // This section is specified/returned if the
  1387.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  1388.     //
  1389.  
  1390.     DWORD   Edi;
  1391.     DWORD   Esi;
  1392.     DWORD   Ebx;
  1393.     DWORD   Edx;
  1394.     DWORD   Ecx;
  1395.     DWORD   Eax;
  1396.  
  1397.     //
  1398.     // This section is specified/returned if the
  1399.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  1400.     //
  1401.  
  1402.     DWORD   Ebp;
  1403.     DWORD   Eip;
  1404.     DWORD   SegCs;              // MUST BE SANITIZED
  1405.     DWORD   EFlags;             // MUST BE SANITIZED
  1406.     DWORD   Esp;
  1407.     DWORD   SegSs;
  1408.  
  1409. } CONTEXT;
  1410.  
  1411.  
  1412.  
  1413. typedef CONTEXT *PCONTEXT;
  1414.  
  1415. // begin_ntminiport
  1416.  
  1417. #endif //_X86_
  1418.  
  1419.  
  1420. typedef struct _LDT_ENTRY {
  1421.     WORD    LimitLow;
  1422.     WORD    BaseLow;
  1423.     union {
  1424.         struct {
  1425.             BYTE    BaseMid;
  1426.             BYTE    Flags1;     // Declare as bytes to avoid alignment
  1427.             BYTE    Flags2;     // Problems.
  1428.             BYTE    BaseHi;
  1429.         } Bytes;
  1430.         struct {
  1431.             DWORD   BaseMid : 8;
  1432.             DWORD   Type : 5;
  1433.             DWORD   Dpl : 2;
  1434.             DWORD   Pres : 1;
  1435.             DWORD   LimitHi : 4;
  1436.             DWORD   Sys : 1;
  1437.             DWORD   Reserved_0 : 1;
  1438.             DWORD   Default_Big : 1;
  1439.             DWORD   Granularity : 1;
  1440.             DWORD   BaseHi : 8;
  1441.         } Bits;
  1442.     } HighWord;
  1443. } LDT_ENTRY, *PLDT_ENTRY;
  1444.  
  1445.  
  1446. #if defined(_MIPS_)
  1447.  
  1448. //
  1449. // Define functions to get the address of the current fiber and the
  1450. // current fiber data.
  1451. //
  1452.  
  1453. #define GetCurrentFiber() ((*(PNT_TIB *)0x7ffff4a8)->FiberData)
  1454. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1455.  
  1456. // begin_ntddk begin_nthal
  1457. //
  1458. // The following flags control the contents of the CONTEXT structure.
  1459. //
  1460.  
  1461. #if !defined(RC_INVOKED)
  1462.  
  1463. #define CONTEXT_R4000   0x00010000    // r4000 context
  1464.  
  1465. #define CONTEXT_CONTROL          (CONTEXT_R4000 | 0x00000001)
  1466. #define CONTEXT_FLOATING_POINT   (CONTEXT_R4000 | 0x00000002)
  1467. #define CONTEXT_INTEGER          (CONTEXT_R4000 | 0x00000004)
  1468. #define CONTEXT_EXTENDED_FLOAT   (CONTEXT_FLOATING_POINT | 0x00000008)
  1469. #define CONTEXT_EXTENDED_INTEGER (CONTEXT_INTEGER | 0x00000010)
  1470.  
  1471. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | \
  1472.                       CONTEXT_INTEGER | CONTEXT_EXTENDED_INTEGER)
  1473.  
  1474. #endif
  1475.  
  1476. //
  1477. // Context Frame
  1478. //
  1479. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1480. //
  1481. //  This frame has a several purposes: 1) it is used as an argument to
  1482. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1483. //  3) it is used to construct a call frame for exception dispatching
  1484. //  in user mode, and 4) it is used in the user level thread creation
  1485. //  routines.
  1486. //
  1487. //  The layout of the record conforms to a standard call frame.
  1488. //
  1489.  
  1490. typedef struct _CONTEXT {
  1491.  
  1492.     //
  1493.     // This section is always present and is used as an argument build
  1494.     // area.
  1495.     //
  1496.     // N.B. Context records are 0 mod 8 aligned starting with NT 4.0.
  1497.     //
  1498.  
  1499.     union {
  1500.         DWORD Argument[4];
  1501.         DWORDLONG Alignment;
  1502.     };
  1503.  
  1504.     //
  1505.     // The following union defines the 32-bit and 64-bit register context.
  1506.     //
  1507.  
  1508.     union {
  1509.  
  1510.         //
  1511.         // 32-bit context.
  1512.         //
  1513.  
  1514.         struct {
  1515.  
  1516.             //
  1517.             // This section is specified/returned if the ContextFlags contains
  1518.             // the flag CONTEXT_FLOATING_POINT.
  1519.             //
  1520.             // N.B. This section contains the 16 double floating registers f0,
  1521.             //      f2, ..., f30.
  1522.             //
  1523.  
  1524.             DWORD FltF0;
  1525.             DWORD FltF1;
  1526.             DWORD FltF2;
  1527.             DWORD FltF3;
  1528.             DWORD FltF4;
  1529.             DWORD FltF5;
  1530.             DWORD FltF6;
  1531.             DWORD FltF7;
  1532.             DWORD FltF8;
  1533.             DWORD FltF9;
  1534.             DWORD FltF10;
  1535.             DWORD FltF11;
  1536.             DWORD FltF12;
  1537.             DWORD FltF13;
  1538.             DWORD FltF14;
  1539.             DWORD FltF15;
  1540.             DWORD FltF16;
  1541.             DWORD FltF17;
  1542.             DWORD FltF18;
  1543.             DWORD FltF19;
  1544.             DWORD FltF20;
  1545.             DWORD FltF21;
  1546.             DWORD FltF22;
  1547.             DWORD FltF23;
  1548.             DWORD FltF24;
  1549.             DWORD FltF25;
  1550.             DWORD FltF26;
  1551.             DWORD FltF27;
  1552.             DWORD FltF28;
  1553.             DWORD FltF29;
  1554.             DWORD FltF30;
  1555.             DWORD FltF31;
  1556.  
  1557.             //
  1558.             // This section is specified/returned if the ContextFlags contains
  1559.             // the flag CONTEXT_INTEGER.
  1560.             //
  1561.             // N.B. The registers gp, sp, and ra are defined in this section,
  1562.             //      but are considered part of the control context rather than
  1563.             //      part of the integer context.
  1564.             //
  1565.             // N.B. Register zero is not stored in the frame.
  1566.             //
  1567.  
  1568.             DWORD IntZero;
  1569.             DWORD IntAt;
  1570.             DWORD IntV0;
  1571.             DWORD IntV1;
  1572.             DWORD IntA0;
  1573.             DWORD IntA1;
  1574.             DWORD IntA2;
  1575.             DWORD IntA3;
  1576.             DWORD IntT0;
  1577.             DWORD IntT1;
  1578.             DWORD IntT2;
  1579.             DWORD IntT3;
  1580.             DWORD IntT4;
  1581.             DWORD IntT5;
  1582.             DWORD IntT6;
  1583.             DWORD IntT7;
  1584.             DWORD IntS0;
  1585.             DWORD IntS1;
  1586.             DWORD IntS2;
  1587.             DWORD IntS3;
  1588.             DWORD IntS4;
  1589.             DWORD IntS5;
  1590.             DWORD IntS6;
  1591.             DWORD IntS7;
  1592.             DWORD IntT8;
  1593.             DWORD IntT9;
  1594.             DWORD IntK0;
  1595.             DWORD IntK1;
  1596.             DWORD IntGp;
  1597.             DWORD IntSp;
  1598.             DWORD IntS8;
  1599.             DWORD IntRa;
  1600.             DWORD IntLo;
  1601.             DWORD IntHi;
  1602.  
  1603.             //
  1604.             // This section is specified/returned if the ContextFlags word contains
  1605.             // the flag CONTEXT_FLOATING_POINT.
  1606.             //
  1607.  
  1608.             DWORD Fsr;
  1609.  
  1610.             //
  1611.             // This section is specified/returned if the ContextFlags word contains
  1612.             // the flag CONTEXT_CONTROL.
  1613.             //
  1614.             // N.B. The registers gp, sp, and ra are defined in the integer section,
  1615.             //   but are considered part of the control context rather than part of
  1616.             //   the integer context.
  1617.             //
  1618.  
  1619.             DWORD Fir;
  1620.             DWORD Psr;
  1621.  
  1622.             //
  1623.             // The flags values within this flag control the contents of
  1624.             // a CONTEXT record.
  1625.             //
  1626.             // If the context record is used as an input parameter, then
  1627.             // for each portion of the context record controlled by a flag
  1628.             // whose value is set, it is assumed that that portion of the
  1629.             // context record contains valid context. If the context record
  1630.             // is being used to modify a thread's context, then only that
  1631.             // portion of the threads context will be modified.
  1632.             //
  1633.             // If the context record is used as an IN OUT parameter to capture
  1634.             // the context of a thread, then only those portions of the thread's
  1635.             // context corresponding to set flags will be returned.
  1636.             //
  1637.             // The context record is never used as an OUT only parameter.
  1638.             //
  1639.  
  1640.             DWORD ContextFlags;
  1641.         };
  1642.  
  1643.         //
  1644.         // 64-bit context.
  1645.         //
  1646.  
  1647.         struct {
  1648.  
  1649.             //
  1650.             // This section is specified/returned if the ContextFlags contains
  1651.             // the flag CONTEXT_EXTENDED_FLOAT.
  1652.             //
  1653.             // N.B. This section contains the 32 double floating registers f0,
  1654.             //      f1, ..., f31.
  1655.             //
  1656.  
  1657.             DWORDLONG XFltF0;
  1658.             DWORDLONG XFltF1;
  1659.             DWORDLONG XFltF2;
  1660.             DWORDLONG XFltF3;
  1661.             DWORDLONG XFltF4;
  1662.             DWORDLONG XFltF5;
  1663.             DWORDLONG XFltF6;
  1664.             DWORDLONG XFltF7;
  1665.             DWORDLONG XFltF8;
  1666.             DWORDLONG XFltF9;
  1667.             DWORDLONG XFltF10;
  1668.             DWORDLONG XFltF11;
  1669.             DWORDLONG XFltF12;
  1670.             DWORDLONG XFltF13;
  1671.             DWORDLONG XFltF14;
  1672.             DWORDLONG XFltF15;
  1673.             DWORDLONG XFltF16;
  1674.             DWORDLONG XFltF17;
  1675.             DWORDLONG XFltF18;
  1676.             DWORDLONG XFltF19;
  1677.             DWORDLONG XFltF20;
  1678.             DWORDLONG XFltF21;
  1679.             DWORDLONG XFltF22;
  1680.             DWORDLONG XFltF23;
  1681.             DWORDLONG XFltF24;
  1682.             DWORDLONG XFltF25;
  1683.             DWORDLONG XFltF26;
  1684.             DWORDLONG XFltF27;
  1685.             DWORDLONG XFltF28;
  1686.             DWORDLONG XFltF29;
  1687.             DWORDLONG XFltF30;
  1688.             DWORDLONG XFltF31;
  1689.  
  1690.             //
  1691.             // The following sections must exactly overlay the 32-bit context.
  1692.             //
  1693.  
  1694.             DWORD Fill1;
  1695.             DWORD Fill2;
  1696.  
  1697.             //
  1698.             // This section is specified/returned if the ContextFlags contains
  1699.             // the flag CONTEXT_FLOATING_POINT.
  1700.             //
  1701.  
  1702.             DWORD XFsr;
  1703.  
  1704.             //
  1705.             // This section is specified/returned if the ContextFlags contains
  1706.             // the flag CONTEXT_CONTROL.
  1707.             //
  1708.             // N.B. The registers gp, sp, and ra are defined in the integer
  1709.             //      section, but are considered part of the control context
  1710.             //      rather than part of the integer context.
  1711.             //
  1712.  
  1713.             DWORD XFir;
  1714.             DWORD XPsr;
  1715.  
  1716.             //
  1717.             // The flags values within this flag control the contents of
  1718.             // a CONTEXT record.
  1719.             //
  1720.             // If the context record is used as an input parameter, then
  1721.             // for each portion of the context record controlled by a flag
  1722.             // whose value is set, it is assumed that that portion of the
  1723.             // context record contains valid context. If the context record
  1724.             // is being used to modify a thread's context, then only that
  1725.             // portion of the threads context will be modified.
  1726.             //
  1727.             // If the context record is used as an IN OUT parameter to capture
  1728.             // the context of a thread, then only those portions of the thread's
  1729.             // context corresponding to set flags will be returned.
  1730.             //
  1731.             // The context record is never used as an OUT only parameter.
  1732.             //
  1733.  
  1734.             DWORD XContextFlags;
  1735.  
  1736.             //
  1737.             // This section is specified/returned if the ContextFlags contains
  1738.             // the flag CONTEXT_EXTENDED_INTEGER.
  1739.             //
  1740.             // N.B. The registers gp, sp, and ra are defined in this section,
  1741.             //      but are considered part of the control context rather than
  1742.             //      part of the integer  context.
  1743.             //
  1744.             // N.B. Register zero is not stored in the frame.
  1745.             //
  1746.  
  1747.             DWORDLONG XIntZero;
  1748.             DWORDLONG XIntAt;
  1749.             DWORDLONG XIntV0;
  1750.             DWORDLONG XIntV1;
  1751.             DWORDLONG XIntA0;
  1752.             DWORDLONG XIntA1;
  1753.             DWORDLONG XIntA2;
  1754.             DWORDLONG XIntA3;
  1755.             DWORDLONG XIntT0;
  1756.             DWORDLONG XIntT1;
  1757.             DWORDLONG XIntT2;
  1758.             DWORDLONG XIntT3;
  1759.             DWORDLONG XIntT4;
  1760.             DWORDLONG XIntT5;
  1761.             DWORDLONG XIntT6;
  1762.             DWORDLONG XIntT7;
  1763.             DWORDLONG XIntS0;
  1764.             DWORDLONG XIntS1;
  1765.             DWORDLONG XIntS2;
  1766.             DWORDLONG XIntS3;
  1767.             DWORDLONG XIntS4;
  1768.             DWORDLONG XIntS5;
  1769.             DWORDLONG XIntS6;
  1770.             DWORDLONG XIntS7;
  1771.             DWORDLONG XIntT8;
  1772.             DWORDLONG XIntT9;
  1773.             DWORDLONG XIntK0;
  1774.             DWORDLONG XIntK1;
  1775.             DWORDLONG XIntGp;
  1776.             DWORDLONG XIntSp;
  1777.             DWORDLONG XIntS8;
  1778.             DWORDLONG XIntRa;
  1779.             DWORDLONG XIntLo;
  1780.             DWORDLONG XIntHi;
  1781.         };
  1782.     };
  1783. } CONTEXT, *PCONTEXT;
  1784.  
  1785. // end_ntddk end_nthal
  1786.  
  1787. #define CONTEXT32_LENGTH 0x130          // The original 32-bit Context length (pre NT 4.0)
  1788.  
  1789. #endif // MIPS
  1790.  
  1791.  
  1792. #if defined(_MIPS_)
  1793.  
  1794. VOID
  1795. __jump_unwind (
  1796.     PVOID Fp,
  1797.     PVOID TargetPc
  1798.     );
  1799.  
  1800. #endif // MIPS
  1801.  
  1802.  
  1803. #if defined(_PPC_)
  1804.  
  1805.  
  1806. //
  1807. // The address of the TEB is placed into GPR 13 at context switch time
  1808. // and should never be destroyed.  To get the address of the TEB use
  1809. // the compiler intrinsic to access it directly from GPR 13.
  1810. //
  1811.  
  1812. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  1813. unsigned __gregister_get( unsigned const regnum );
  1814. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  1815. #elif defined(_M_PPC)
  1816. struct _TEB * __builtin_get_gpr13(VOID);
  1817. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  1818. #endif
  1819.  
  1820.  
  1821. //
  1822. // Define functions to get the address of the current fiber and the
  1823. // current fiber data.
  1824. //
  1825.  
  1826. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  1827. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1828.  
  1829. // begin_ntddk begin_nthal
  1830. //
  1831. // The following flags control the contents of the CONTEXT structure.
  1832. //
  1833.  
  1834. #if !defined(RC_INVOKED)
  1835.  
  1836. #define CONTEXT_CONTROL         0x00000001L
  1837. #define CONTEXT_FLOATING_POINT  0x00000002L
  1838. #define CONTEXT_INTEGER         0x00000004L
  1839. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  1840.  
  1841. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1842.  
  1843. #endif
  1844.  
  1845. //
  1846. // Context Frame
  1847. //
  1848. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1849. //
  1850. //  This frame has a several purposes: 1) it is used as an argument to
  1851. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1852. //  3) it is used to construct a call frame for exception dispatching
  1853. //  in user mode, and 4) it is used in the user level thread creation
  1854. //  routines.
  1855. //
  1856. //  Requires at least 8-byte alignment (double)
  1857. //
  1858.  
  1859. typedef struct _CONTEXT {
  1860.  
  1861.     //
  1862.     // This section is specified/returned if the ContextFlags word contains
  1863.     // the flag CONTEXT_FLOATING_POINT.
  1864.     //
  1865.  
  1866.     double Fpr0;                        // Floating registers 0..31
  1867.     double Fpr1;
  1868.     double Fpr2;
  1869.     double Fpr3;
  1870.     double Fpr4;
  1871.     double Fpr5;
  1872.     double Fpr6;
  1873.     double Fpr7;
  1874.     double Fpr8;
  1875.     double Fpr9;
  1876.     double Fpr10;
  1877.     double Fpr11;
  1878.     double Fpr12;
  1879.     double Fpr13;
  1880.     double Fpr14;
  1881.     double Fpr15;
  1882.     double Fpr16;
  1883.     double Fpr17;
  1884.     double Fpr18;
  1885.     double Fpr19;
  1886.     double Fpr20;
  1887.     double Fpr21;
  1888.     double Fpr22;
  1889.     double Fpr23;
  1890.     double Fpr24;
  1891.     double Fpr25;
  1892.     double Fpr26;
  1893.     double Fpr27;
  1894.     double Fpr28;
  1895.     double Fpr29;
  1896.     double Fpr30;
  1897.     double Fpr31;
  1898.     double Fpscr;                       // Floating point status/control reg
  1899.  
  1900.     //
  1901.     // This section is specified/returned if the ContextFlags word contains
  1902.     // the flag CONTEXT_INTEGER.
  1903.     //
  1904.  
  1905.     DWORD Gpr0;                         // General registers 0..31
  1906.     DWORD Gpr1;
  1907.     DWORD Gpr2;
  1908.     DWORD Gpr3;
  1909.     DWORD Gpr4;
  1910.     DWORD Gpr5;
  1911.     DWORD Gpr6;
  1912.     DWORD Gpr7;
  1913.     DWORD Gpr8;
  1914.     DWORD Gpr9;
  1915.     DWORD Gpr10;
  1916.     DWORD Gpr11;
  1917.     DWORD Gpr12;
  1918.     DWORD Gpr13;
  1919.     DWORD Gpr14;
  1920.     DWORD Gpr15;
  1921.     DWORD Gpr16;
  1922.     DWORD Gpr17;
  1923.     DWORD Gpr18;
  1924.     DWORD Gpr19;
  1925.     DWORD Gpr20;
  1926.     DWORD Gpr21;
  1927.     DWORD Gpr22;
  1928.     DWORD Gpr23;
  1929.     DWORD Gpr24;
  1930.     DWORD Gpr25;
  1931.     DWORD Gpr26;
  1932.     DWORD Gpr27;
  1933.     DWORD Gpr28;
  1934.     DWORD Gpr29;
  1935.     DWORD Gpr30;
  1936.     DWORD Gpr31;
  1937.  
  1938.     DWORD Cr;                           // Condition register
  1939.     DWORD Xer;                          // Fixed point exception register
  1940.  
  1941.     //
  1942.     // This section is specified/returned if the ContextFlags word contains
  1943.     // the flag CONTEXT_CONTROL.
  1944.     //
  1945.  
  1946.     DWORD Msr;                          // Machine status register
  1947.     DWORD Iar;                          // Instruction address register
  1948.     DWORD Lr;                           // Link register
  1949.     DWORD Ctr;                          // Count register
  1950.  
  1951.     //
  1952.     // The flags values within this flag control the contents of
  1953.     // a CONTEXT record.
  1954.     //
  1955.     // If the context record is used as an input parameter, then
  1956.     // for each portion of the context record controlled by a flag
  1957.     // whose value is set, it is assumed that that portion of the
  1958.     // context record contains valid context. If the context record
  1959.     // is being used to modify a thread's context, then only that
  1960.     // portion of the threads context will be modified.
  1961.     //
  1962.     // If the context record is used as an IN OUT parameter to capture
  1963.     // the context of a thread, then only those portions of the thread's
  1964.     // context corresponding to set flags will be returned.
  1965.     //
  1966.     // The context record is never used as an OUT only parameter.
  1967.     //
  1968.  
  1969.     DWORD ContextFlags;
  1970.  
  1971.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  1972.  
  1973.     //
  1974.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1975.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1976.     // included in CONTEXT_FULL.
  1977.     //
  1978.     DWORD Dr0;                          // Breakpoint Register 1
  1979.     DWORD Dr1;                          // Breakpoint Register 2
  1980.     DWORD Dr2;                          // Breakpoint Register 3
  1981.     DWORD Dr3;                          // Breakpoint Register 4
  1982.     DWORD Dr4;                          // Breakpoint Register 5
  1983.     DWORD Dr5;                          // Breakpoint Register 6
  1984.     DWORD Dr6;                          // Debug Status Register
  1985.     DWORD Dr7;                          // Debug Control Register
  1986.  
  1987. } CONTEXT, *PCONTEXT;
  1988.  
  1989. // end_ntddk end_nthal
  1990.  
  1991.  
  1992. //
  1993. // Stack frame header
  1994. //
  1995. //   Order of appearance in stack frame:
  1996. //      Header (six words)
  1997. //      Parameters (at least eight words)
  1998. //      Local variables
  1999. //      Saved GPRs
  2000. //      Saved FPRs
  2001. //
  2002. //   Minimum alignment is 8 bytes
  2003.  
  2004. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  2005.     DWORD BackChain;                    // Addr of previous frame
  2006.     DWORD GlueSaved1;                   // Used by glue code
  2007.     DWORD GlueSaved2;
  2008.     DWORD Reserved1;                    // Reserved
  2009.     DWORD Spare1;                       // Used by tracing, profiling, ...
  2010.     DWORD Spare2;
  2011.  
  2012.     DWORD Parameter0;                   // First 8 parameter words are
  2013.     DWORD Parameter1;                   //   always present
  2014.     DWORD Parameter2;
  2015.     DWORD Parameter3;
  2016.     DWORD Parameter4;
  2017.     DWORD Parameter5;
  2018.     DWORD Parameter6;
  2019.     DWORD Parameter7;
  2020.  
  2021. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2022.  
  2023.  
  2024. VOID
  2025. __jump_unwind (
  2026.     PVOID Fp,
  2027.     PVOID TargetPc
  2028.     );
  2029.  
  2030. #endif // defined(_PPC_)
  2031. #define EXCEPTION_NONCONTINUABLE 0x1    // Noncontinuable exception
  2032. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  2033.  
  2034. //
  2035. // Exception record definition.
  2036. //
  2037.  
  2038. typedef struct _EXCEPTION_RECORD {
  2039.     /*lint -e18 */  // Don't complain about different definitions
  2040.     DWORD    ExceptionCode;
  2041.     /*lint +e18 */  // Resume checking for different definitions
  2042.     DWORD ExceptionFlags;
  2043.     struct _EXCEPTION_RECORD *ExceptionRecord;
  2044.     PVOID ExceptionAddress;
  2045.     DWORD NumberParameters;
  2046.     DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  2047.     } EXCEPTION_RECORD;
  2048.  
  2049. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  2050.  
  2051. //
  2052. // Typedef for pointer returned by exception_info()
  2053. //
  2054.  
  2055. typedef struct _EXCEPTION_POINTERS {
  2056.     PEXCEPTION_RECORD ExceptionRecord;
  2057.     PCONTEXT ContextRecord;
  2058. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  2059. #define PROCESS_TERMINATE         (0x0001)  
  2060. #define PROCESS_CREATE_THREAD     (0x0002)  
  2061. #define PROCESS_VM_OPERATION      (0x0008)  
  2062. #define PROCESS_VM_READ           (0x0010)  
  2063. #define PROCESS_VM_WRITE          (0x0020)  
  2064. #define PROCESS_DUP_HANDLE        (0x0040)  
  2065. #define PROCESS_CREATE_PROCESS    (0x0080)  
  2066. #define PROCESS_SET_QUOTA         (0x0100)  
  2067. #define PROCESS_SET_INFORMATION   (0x0200)  
  2068. #define PROCESS_QUERY_INFORMATION (0x0400)  
  2069. #define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  2070.                                    0xFFF)
  2071.  
  2072.  
  2073. #define MAXIMUM_PROCESSORS 32
  2074.  
  2075. #define THREAD_TERMINATE               (0x0001)  
  2076. #define THREAD_SUSPEND_RESUME          (0x0002)  
  2077. #define THREAD_GET_CONTEXT             (0x0008)  
  2078. #define THREAD_SET_CONTEXT             (0x0010)  
  2079. #define THREAD_SET_INFORMATION         (0x0020)  
  2080. #define THREAD_QUERY_INFORMATION       (0x0040)  
  2081. #define THREAD_SET_THREAD_TOKEN        (0x0080)
  2082. #define THREAD_IMPERSONATE             (0x0100)
  2083. #define THREAD_DIRECT_IMPERSONATION    (0x0200)
  2084. // begin_ntddk
  2085.  
  2086. #define THREAD_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  2087.                                    0x3FF)
  2088.  
  2089. // end_ntddk
  2090. #define TLS_MINIMUM_AVAILABLE 64    
  2091.  
  2092. typedef struct _NT_TIB {
  2093.     struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  2094.     PVOID StackBase;
  2095.     PVOID StackLimit;
  2096.     PVOID SubSystemTib;
  2097.     union {
  2098.         PVOID FiberData;
  2099.         DWORD Version;
  2100.     };
  2101.     PVOID ArbitraryUserPointer;
  2102.     struct _NT_TIB *Self;
  2103. } NT_TIB;
  2104. typedef NT_TIB *PNT_TIB;
  2105. #define THREAD_BASE_PRIORITY_LOWRT  15  // value that gets a thread to LowRealtime-1
  2106. #define THREAD_BASE_PRIORITY_MAX    2   // maximum thread base priority boost
  2107. #define THREAD_BASE_PRIORITY_MIN    -2  // minimum thread base priority boost
  2108. #define THREAD_BASE_PRIORITY_IDLE   -15 // value that gets a thread to idle
  2109.  
  2110. typedef struct _QUOTA_LIMITS {
  2111.     DWORD PagedPoolLimit;
  2112.     DWORD NonPagedPoolLimit;
  2113.     DWORD MinimumWorkingSetSize;
  2114.     DWORD MaximumWorkingSetSize;
  2115.     DWORD PagefileLimit;
  2116.     LARGE_INTEGER TimeLimit;
  2117. } QUOTA_LIMITS;
  2118. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  2119.  
  2120. #define EVENT_MODIFY_STATE      0x0002  
  2121. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  2122. #define MUTANT_QUERY_STATE      0x0001
  2123.  
  2124. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  2125.                           MUTANT_QUERY_STATE)
  2126. #define SEMAPHORE_MODIFY_STATE      0x0002  
  2127. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  2128. #define TIME_ZONE_ID_UNKNOWN  0
  2129. #define TIME_ZONE_ID_STANDARD 1
  2130. #define TIME_ZONE_ID_DAYLIGHT 2
  2131.  
  2132. #define PROCESSOR_INTEL_386     386
  2133. #define PROCESSOR_INTEL_486     486
  2134. #define PROCESSOR_INTEL_PENTIUM 586
  2135. #define PROCESSOR_MIPS_R4000    4000
  2136. #define PROCESSOR_ALPHA_21064   21064
  2137.  
  2138. #define PROCESSOR_ARCHITECTURE_INTEL 0
  2139. #define PROCESSOR_ARCHITECTURE_MIPS  1
  2140. #define PROCESSOR_ARCHITECTURE_ALPHA 2
  2141. #define PROCESSOR_ARCHITECTURE_PPC   3
  2142. #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
  2143.  
  2144. #define PF_FLOATING_POINT_PRECISION_ERRATA  0   
  2145. #define PF_FLOATING_POINT_EMULATED          1   
  2146. #define PF_COMPARE_EXCHANGE_DOUBLE          2   
  2147. #define PF_MMX_INSTRUCTIONS_AVAILABLE       3   
  2148. typedef struct _MEMORY_BASIC_INFORMATION {
  2149.     PVOID BaseAddress;
  2150.     PVOID AllocationBase;
  2151.     DWORD AllocationProtect;
  2152.     DWORD RegionSize;
  2153.     DWORD State;
  2154.     DWORD Protect;
  2155.     DWORD Type;
  2156. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  2157. #define SECTION_QUERY       0x0001
  2158. #define SECTION_MAP_WRITE   0x0002
  2159. #define SECTION_MAP_READ    0x0004
  2160. #define SECTION_MAP_EXECUTE 0x0008
  2161. #define SECTION_EXTEND_SIZE 0x0010
  2162.  
  2163. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  2164.                             SECTION_MAP_WRITE |      \
  2165.                             SECTION_MAP_READ |       \
  2166.                             SECTION_MAP_EXECUTE |    \
  2167.                             SECTION_EXTEND_SIZE)
  2168. #define PAGE_NOACCESS          0x01     
  2169. #define PAGE_READONLY          0x02     
  2170. #define PAGE_READWRITE         0x04     
  2171. #define PAGE_WRITECOPY         0x08     
  2172. #define PAGE_EXECUTE           0x10     
  2173. #define PAGE_EXECUTE_READ      0x20     
  2174. #define PAGE_EXECUTE_READWRITE 0x40     
  2175. #define PAGE_EXECUTE_WRITECOPY 0x80     
  2176. #define PAGE_GUARD            0x100     
  2177. #define PAGE_NOCACHE          0x200     
  2178. #define MEM_COMMIT           0x1000     
  2179. #define MEM_RESERVE          0x2000     
  2180. #define MEM_DECOMMIT         0x4000     
  2181. #define MEM_RELEASE          0x8000     
  2182. #define MEM_FREE            0x10000     
  2183. #define MEM_PRIVATE         0x20000     
  2184. #define MEM_MAPPED          0x40000     
  2185. #define MEM_RESET           0x80000     
  2186. #define MEM_TOP_DOWN       0x100000     
  2187. #define SEC_FILE           0x800000     
  2188. #define SEC_IMAGE         0x1000000     
  2189. #define SEC_RESERVE       0x4000000     
  2190. #define SEC_COMMIT        0x8000000     
  2191. #define SEC_NOCACHE      0x10000000     
  2192. #define MEM_IMAGE         SEC_IMAGE     
  2193.  
  2194. //
  2195. // Define access rights to files and directories
  2196. //
  2197.  
  2198. //
  2199. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  2200. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  2201. // constants *MUST* always be in sync.
  2202. // The values are redefined in devioctl.h because they must be available to
  2203. // both DOS and NT.
  2204. //
  2205.  
  2206. #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
  2207. #define FILE_LIST_DIRECTORY       ( 0x0001 )    // directory
  2208.  
  2209. #define FILE_WRITE_DATA           ( 0x0002 )    // file & pipe
  2210. #define FILE_ADD_FILE             ( 0x0002 )    // directory
  2211.  
  2212. #define FILE_APPEND_DATA          ( 0x0004 )    // file
  2213. #define FILE_ADD_SUBDIRECTORY     ( 0x0004 )    // directory
  2214. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 )    // named pipe
  2215.  
  2216. #define FILE_READ_EA              ( 0x0008 )    // file & directory
  2217.  
  2218. #define FILE_WRITE_EA             ( 0x0010 )    // file & directory
  2219.  
  2220. #define FILE_EXECUTE              ( 0x0020 )    // file
  2221. #define FILE_TRAVERSE             ( 0x0020 )    // directory
  2222.  
  2223. #define FILE_DELETE_CHILD         ( 0x0040 )    // directory
  2224.  
  2225. #define FILE_READ_ATTRIBUTES      ( 0x0080 )    // all
  2226.  
  2227. #define FILE_WRITE_ATTRIBUTES     ( 0x0100 )    // all
  2228.  
  2229. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  2230.  
  2231. #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ     |\
  2232.                                    FILE_READ_DATA           |\
  2233.                                    FILE_READ_ATTRIBUTES     |\
  2234.                                    FILE_READ_EA             |\
  2235.                                    SYNCHRONIZE)
  2236.  
  2237.  
  2238. #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE    |\
  2239.                                    FILE_WRITE_DATA          |\
  2240.                                    FILE_WRITE_ATTRIBUTES    |\
  2241.                                    FILE_WRITE_EA            |\
  2242.                                    FILE_APPEND_DATA         |\
  2243.                                    SYNCHRONIZE)
  2244.  
  2245.  
  2246. #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE  |\
  2247.                                    FILE_READ_ATTRIBUTES     |\
  2248.                                    FILE_EXECUTE             |\
  2249.                                    SYNCHRONIZE)
  2250.  
  2251. #define FILE_SHARE_READ                 0x00000001  
  2252. #define FILE_SHARE_WRITE                0x00000002  
  2253. #define FILE_SHARE_DELETE               0x00000004  
  2254. #define FILE_ATTRIBUTE_READONLY         0x00000001  
  2255. #define FILE_ATTRIBUTE_HIDDEN           0x00000002  
  2256. #define FILE_ATTRIBUTE_SYSTEM           0x00000004  
  2257. #define FILE_ATTRIBUTE_DIRECTORY        0x00000010  
  2258. #define FILE_ATTRIBUTE_ARCHIVE          0x00000020  
  2259. #define FILE_ATTRIBUTE_NORMAL           0x00000080  
  2260. #define FILE_ATTRIBUTE_TEMPORARY        0x00000100  
  2261. #define FILE_ATTRIBUTE_COMPRESSED       0x00000800  
  2262. #define FILE_ATTRIBUTE_OFFLINE          0x00001000  
  2263. #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001   
  2264. #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002   
  2265. #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004   
  2266. #define FILE_NOTIFY_CHANGE_SIZE         0x00000008   
  2267. #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010   
  2268. #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020   
  2269. #define FILE_NOTIFY_CHANGE_CREATION     0x00000040   
  2270. #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100   
  2271. #define FILE_ACTION_ADDED               0x00000001   
  2272. #define FILE_ACTION_REMOVED             0x00000002   
  2273. #define FILE_ACTION_MODIFIED            0x00000003   
  2274. #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004   
  2275. #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005   
  2276. #define MAILSLOT_NO_MESSAGE             ((DWORD)-1) 
  2277. #define MAILSLOT_WAIT_FOREVER           ((DWORD)-1) 
  2278. #define FILE_CASE_SENSITIVE_SEARCH      0x00000001  
  2279. #define FILE_CASE_PRESERVED_NAMES       0x00000002  
  2280. #define FILE_UNICODE_ON_DISK            0x00000004  
  2281. #define FILE_PERSISTENT_ACLS            0x00000008  
  2282. #define FILE_FILE_COMPRESSION           0x00000010  
  2283. #define FILE_VOLUME_IS_COMPRESSED       0x00008000  
  2284.  
  2285. //
  2286. // Define the file notification information structure
  2287. //
  2288.  
  2289. typedef struct _FILE_NOTIFY_INFORMATION {
  2290.     DWORD NextEntryOffset;
  2291.     DWORD Action;
  2292.     DWORD FileNameLength;
  2293.     WCHAR FileName[1];
  2294. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  2295.  
  2296. #define IO_COMPLETION_MODIFY_STATE  0x0002  
  2297. #define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  2298. #define DUPLICATE_CLOSE_SOURCE      0x00000001  
  2299. #define DUPLICATE_SAME_ACCESS       0x00000002  
  2300. typedef PVOID PACCESS_TOKEN;            
  2301. typedef PVOID PSECURITY_DESCRIPTOR;     
  2302. typedef PVOID PSID;     
  2303. ////////////////////////////////////////////////////////////////////////
  2304. //                                                                    //
  2305. //                             ACCESS MASK                            //
  2306. //                                                                    //
  2307. ////////////////////////////////////////////////////////////////////////
  2308.  
  2309. //
  2310. //  Define the access mask as a longword sized structure divided up as
  2311. //  follows:
  2312. //
  2313. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2314. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  2315. //      +---------------+---------------+-------------------------------+
  2316. //      |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
  2317. //      |R|W|E|A|     |S|               |                               |
  2318. //      +-+-------------+---------------+-------------------------------+
  2319. //
  2320. //      typedef struct _ACCESS_MASK {
  2321. //          WORD   SpecificRights;
  2322. //          BYTE  StandardRights;
  2323. //          BYTE  AccessSystemAcl : 1;
  2324. //          BYTE  Reserved : 3;
  2325. //          BYTE  GenericAll : 1;
  2326. //          BYTE  GenericExecute : 1;
  2327. //          BYTE  GenericWrite : 1;
  2328. //          BYTE  GenericRead : 1;
  2329. //      } ACCESS_MASK;
  2330. //      typedef ACCESS_MASK *PACCESS_MASK;
  2331. //
  2332. //  but to make life simple for programmer's we'll allow them to specify
  2333. //  a desired access mask by simply OR'ing together mulitple single rights
  2334. //  and treat an access mask as a DWORD.  For example
  2335. //
  2336. //      DesiredAccess = DELETE | READ_CONTROL
  2337. //
  2338. //  So we'll declare ACCESS_MASK as DWORD
  2339. //
  2340.  
  2341. // begin_ntddk begin_nthal begin_ntifs
  2342. typedef DWORD ACCESS_MASK;
  2343. typedef ACCESS_MASK *PACCESS_MASK;
  2344.  
  2345. ////////////////////////////////////////////////////////////////////////
  2346. //                                                                    //
  2347. //                             ACCESS TYPES                           //
  2348. //                                                                    //
  2349. ////////////////////////////////////////////////////////////////////////
  2350.  
  2351.  
  2352. // begin_ntddk begin_nthal begin_ntifs
  2353. //
  2354. //  The following are masks for the predefined standard access types
  2355. //
  2356.  
  2357. #define DELETE                           (0x00010000L)
  2358. #define READ_CONTROL                     (0x00020000L)
  2359. #define WRITE_DAC                        (0x00040000L)
  2360. #define WRITE_OWNER                      (0x00080000L)
  2361. #define SYNCHRONIZE                      (0x00100000L)
  2362.  
  2363. #define STANDARD_RIGHTS_REQUIRED         (0x000F0000L)
  2364.  
  2365. #define STANDARD_RIGHTS_READ             (READ_CONTROL)
  2366. #define STANDARD_RIGHTS_WRITE            (READ_CONTROL)
  2367. #define STANDARD_RIGHTS_EXECUTE          (READ_CONTROL)
  2368.  
  2369. #define STANDARD_RIGHTS_ALL              (0x001F0000L)
  2370.  
  2371. #define SPECIFIC_RIGHTS_ALL              (0x0000FFFFL)
  2372.  
  2373. //
  2374. // AccessSystemAcl access type
  2375. //
  2376.  
  2377. #define ACCESS_SYSTEM_SECURITY           (0x01000000L)
  2378.  
  2379. //
  2380. // MaximumAllowed access type
  2381. //
  2382.  
  2383. #define MAXIMUM_ALLOWED                  (0x02000000L)
  2384.  
  2385. //
  2386. //  These are the generic rights.
  2387. //
  2388.  
  2389. #define GENERIC_READ                     (0x80000000L)
  2390. #define GENERIC_WRITE                    (0x40000000L)
  2391. #define GENERIC_EXECUTE                  (0x20000000L)
  2392. #define GENERIC_ALL                      (0x10000000L)
  2393.  
  2394.  
  2395. //
  2396. //  Define the generic mapping array.  This is used to denote the
  2397. //  mapping of each generic access right to a specific access mask.
  2398. //
  2399.  
  2400. typedef struct _GENERIC_MAPPING {
  2401.     ACCESS_MASK GenericRead;
  2402.     ACCESS_MASK GenericWrite;
  2403.     ACCESS_MASK GenericExecute;
  2404.     ACCESS_MASK GenericAll;
  2405. } GENERIC_MAPPING;
  2406. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  2407.  
  2408.  
  2409.  
  2410. ////////////////////////////////////////////////////////////////////////
  2411. //                                                                    //
  2412. //                        LUID_AND_ATTRIBUTES                         //
  2413. //                                                                    //
  2414. ////////////////////////////////////////////////////////////////////////
  2415. //
  2416. //
  2417.  
  2418.  
  2419. #include <pshpack4.h>
  2420.  
  2421. typedef struct _LUID_AND_ATTRIBUTES {
  2422.     LUID Luid;
  2423.     DWORD Attributes;
  2424.     } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  2425. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  2426. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  2427.  
  2428. #include <poppack.h>
  2429.  
  2430.  
  2431. ////////////////////////////////////////////////////////////////////////
  2432. //                                                                    //
  2433. //              Security Id     (SID)                                 //
  2434. //                                                                    //
  2435. ////////////////////////////////////////////////////////////////////////
  2436. //
  2437. //
  2438. // Pictorially the structure of an SID is as follows:
  2439. //
  2440. //         1   1   1   1   1   1
  2441. //         5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
  2442. //      +---------------------------------------------------------------+
  2443. //      |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
  2444. //      +---------------------------------------------------------------+
  2445. //      |                   IdentifierAuthority[0]                      |
  2446. //      +---------------------------------------------------------------+
  2447. //      |                   IdentifierAuthority[1]                      |
  2448. //      +---------------------------------------------------------------+
  2449. //      |                   IdentifierAuthority[2]                      |
  2450. //      +---------------------------------------------------------------+
  2451. //      |                                                               |
  2452. //      +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
  2453. //      |                                                               |
  2454. //      +---------------------------------------------------------------+
  2455. //
  2456. //
  2457.  
  2458.  
  2459. // begin_ntifs
  2460.  
  2461. typedef struct _SID_IDENTIFIER_AUTHORITY {
  2462.     BYTE  Value[6];
  2463. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  2464.  
  2465.  
  2466. typedef struct _SID {
  2467.    BYTE  Revision;
  2468.    BYTE  SubAuthorityCount;
  2469.    SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  2470. #ifdef MIDL_PASS
  2471.    [size_is(SubAuthorityCount)] DWORD SubAuthority[*];
  2472. #else // MIDL_PASS
  2473.    DWORD SubAuthority[ANYSIZE_ARRAY];
  2474. #endif // MIDL_PASS
  2475. } SID, *PISID;
  2476.  
  2477.  
  2478. #define SID_REVISION                     (1)    // Current revision level
  2479. #define SID_MAX_SUB_AUTHORITIES          (15)
  2480. #define SID_RECOMMENDED_SUB_AUTHORITIES  (1)    // Will change to around 6
  2481.                                                 // in a future release.
  2482.  
  2483. typedef enum _SID_NAME_USE {
  2484.     SidTypeUser = 1,
  2485.     SidTypeGroup,
  2486.     SidTypeDomain,
  2487.     SidTypeAlias,
  2488.     SidTypeWellKnownGroup,
  2489.     SidTypeDeletedAccount,
  2490.     SidTypeInvalid,
  2491.     SidTypeUnknown
  2492. } SID_NAME_USE, *PSID_NAME_USE;
  2493.  
  2494. typedef struct _SID_AND_ATTRIBUTES {
  2495.     PSID Sid;
  2496.     DWORD Attributes;
  2497.     } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  2498.  
  2499. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  2500. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  2501.  
  2502.  
  2503.  
  2504. /////////////////////////////////////////////////////////////////////////////
  2505. //                                                                         //
  2506. // Universal well-known SIDs                                               //
  2507. //                                                                         //
  2508. //     Null SID                     S-1-0-0                                //
  2509. //     World                        S-1-1-0                                //
  2510. //     Local                        S-1-2-0                                //
  2511. //     Creator Owner ID             S-1-3-0                                //
  2512. //     Creator Group ID             S-1-3-1                                //
  2513. //     Creator Owner Server ID      S-1-3-2                                //
  2514. //     Creator Group Server ID      S-1-3-3                                //
  2515. //                                                                         //
  2516. //     (Non-unique IDs)             S-1-4                                  //
  2517. //                                                                         //
  2518. /////////////////////////////////////////////////////////////////////////////
  2519.  
  2520. #define SECURITY_NULL_SID_AUTHORITY       {0,0,0,0,0,0}
  2521. #define SECURITY_WORLD_SID_AUTHORITY      {0,0,0,0,0,1}
  2522. #define SECURITY_LOCAL_SID_AUTHORITY      {0,0,0,0,0,2}
  2523. #define SECURITY_CREATOR_SID_AUTHORITY    {0,0,0,0,0,3}
  2524. #define SECURITY_NON_UNIQUE_AUTHORITY     {0,0,0,0,0,4}
  2525.  
  2526. #define SECURITY_NULL_RID                 (0x00000000L)
  2527. #define SECURITY_WORLD_RID                (0x00000000L)
  2528. #define SECURITY_LOCAL_RID                (0X00000000L)
  2529.  
  2530. #define SECURITY_CREATOR_OWNER_RID        (0x00000000L)
  2531. #define SECURITY_CREATOR_GROUP_RID        (0x00000001L)
  2532.  
  2533. #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
  2534. #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)
  2535.  
  2536.  
  2537. /////////////////////////////////////////////////////////////////////////////
  2538. //                                                                         //
  2539. // NT well-known SIDs                                                      //
  2540. //                                                                         //
  2541. //     NT Authority          S-1-5                                         //
  2542. //     Dialup                S-1-5-1                                       //
  2543. //                                                                         //
  2544. //     Network               S-1-5-2                                       //
  2545. //     Batch                 S-1-5-3                                       //
  2546. //     Interactive           S-1-5-4                                       //
  2547. //     Service               S-1-5-6                                       //
  2548. //     AnonymousLogon        S-1-5-7       (aka null logon session)        //
  2549. //     Proxy                 S-1-5-8                                       //
  2550. //     ServerLogon           S-1-5-8       (aka domain controller account) //
  2551. //                                                                         //
  2552. //     (Logon IDs)           S-1-5-5-X-Y                                   //
  2553. //                                                                         //
  2554. //     (NT non-unique IDs)   S-1-5-0x15-...                                //
  2555. //                                                                         //
  2556. //     (Built-in domain)     s-1-5-0x20                                    //
  2557. //                                                                         //
  2558. /////////////////////////////////////////////////////////////////////////////
  2559.  
  2560.  
  2561. #define SECURITY_NT_AUTHORITY           {0,0,0,0,0,5}   // ntifs
  2562.  
  2563. #define SECURITY_DIALUP_RID             (0x00000001L)
  2564. #define SECURITY_NETWORK_RID            (0x00000002L)
  2565. #define SECURITY_BATCH_RID              (0x00000003L)
  2566. #define SECURITY_INTERACTIVE_RID        (0x00000004L)
  2567. #define SECURITY_SERVICE_RID            (0x00000006L)
  2568. #define SECURITY_ANONYMOUS_LOGON_RID    (0x00000007L)
  2569. #define SECURITY_PROXY_RID              (0x00000008L)
  2570. #define SECURITY_SERVER_LOGON_RID       (0x00000009L)
  2571.  
  2572. #define SECURITY_LOGON_IDS_RID          (0x00000005L)
  2573. #define SECURITY_LOGON_IDS_RID_COUNT    (3L)
  2574.  
  2575. #define SECURITY_LOCAL_SYSTEM_RID       (0x00000012L)
  2576.  
  2577. #define SECURITY_NT_NON_UNIQUE          (0x00000015L)
  2578.  
  2579. #define SECURITY_BUILTIN_DOMAIN_RID     (0x00000020L)
  2580.  
  2581.  
  2582.  
  2583.  
  2584.  
  2585. /////////////////////////////////////////////////////////////////////////////
  2586. //                                                                         //
  2587. // well-known domain relative sub-authority values (RIDs)...               //
  2588. //                                                                         //
  2589. /////////////////////////////////////////////////////////////////////////////
  2590.  
  2591. // Well-known users ...
  2592.  
  2593. #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
  2594. #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
  2595.  
  2596.  
  2597.  
  2598. // well-known groups ...
  2599.  
  2600. #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
  2601. #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
  2602. #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
  2603.  
  2604.  
  2605.  
  2606.  
  2607. // well-known aliases ...
  2608.  
  2609. #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
  2610. #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
  2611. #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
  2612. #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
  2613.  
  2614. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
  2615. #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
  2616. #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
  2617. #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
  2618.  
  2619. #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626. //
  2627. // Allocate the System Luid.  The first 1000 LUIDs are reserved.
  2628. // Use #999 here (0x3E7 = 999)
  2629. //
  2630.  
  2631. #define SYSTEM_LUID                     { 0x3E7, 0x0 }
  2632.  
  2633. // end_ntifs
  2634.  
  2635. ////////////////////////////////////////////////////////////////////////
  2636. //                                                                    //
  2637. //                          User and Group related SID attributes     //
  2638. //                                                                    //
  2639. ////////////////////////////////////////////////////////////////////////
  2640.  
  2641. //
  2642. // Group attributes
  2643. //
  2644.  
  2645. #define SE_GROUP_MANDATORY              (0x00000001L)
  2646. #define SE_GROUP_ENABLED_BY_DEFAULT     (0x00000002L)
  2647. #define SE_GROUP_ENABLED                (0x00000004L)
  2648. #define SE_GROUP_OWNER                  (0x00000008L)
  2649. #define SE_GROUP_LOGON_ID               (0xC0000000L)
  2650.  
  2651.  
  2652.  
  2653. //
  2654. // User attributes
  2655. //
  2656.  
  2657. // (None yet defined.)
  2658.  
  2659.  
  2660.  
  2661.  
  2662. ////////////////////////////////////////////////////////////////////////
  2663. //                                                                    //
  2664. //                         ACL  and  ACE                              //
  2665. //                                                                    //
  2666. ////////////////////////////////////////////////////////////////////////
  2667.  
  2668. //
  2669. //  Define an ACL and the ACE format.  The structure of an ACL header
  2670. //  followed by one or more ACEs.  Pictorally the structure of an ACL header
  2671. //  is as follows:
  2672. //
  2673. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2674. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  2675. //      +-------------------------------+---------------+---------------+
  2676. //      |            AclSize            |      Sbz1     |  AclRevision  |
  2677. //      +-------------------------------+---------------+---------------+
  2678. //      |              Sbz2             |           AceCount            |
  2679. //      +-------------------------------+-------------------------------+
  2680. //
  2681. //  The current AclRevision is defined to be ACL_REVISION.
  2682. //
  2683. //  AclSize is the size, in bytes, allocated for the ACL.  This includes
  2684. //  the ACL header, ACES, and remaining free space in the buffer.
  2685. //
  2686. //  AceCount is the number of ACES in the ACL.
  2687. //
  2688.  
  2689. // begin_ntddk begin_ntifs
  2690. // This is the *current* ACL revision
  2691.  
  2692. #define ACL_REVISION     (2)
  2693.  
  2694. // This is the history of ACL revisions.  Add a new one whenever
  2695. // ACL_REVISION is updated
  2696.  
  2697. #define ACL_REVISION1   (1)
  2698. #define ACL_REVISION2   (2)
  2699. #define ACL_REVISION3   (3)
  2700.  
  2701. typedef struct _ACL {
  2702.     BYTE  AclRevision;
  2703.     BYTE  Sbz1;
  2704.     WORD   AclSize;
  2705.     WORD   AceCount;
  2706.     WORD   Sbz2;
  2707. } ACL;
  2708. typedef ACL *PACL;
  2709.  
  2710. // end_ntddk
  2711.  
  2712. //
  2713. //  The structure of an ACE is a common ace header followed by ace type
  2714. //  specific data.  Pictorally the structure of the common ace header is
  2715. //  as follows:
  2716. //
  2717. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2718. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  2719. //      +---------------+-------+-------+---------------+---------------+
  2720. //      |            AceSize            |    AceFlags   |     AceType   |
  2721. //      +---------------+-------+-------+---------------+---------------+
  2722. //
  2723. //  AceType denotes the type of the ace, there are some predefined ace
  2724. //  types
  2725. //
  2726. //  AceSize is the size, in bytes, of ace.
  2727. //
  2728. //  AceFlags are the Ace flags for audit and inheritance, defined shortly.
  2729.  
  2730. typedef struct _ACE_HEADER {
  2731.     BYTE  AceType;
  2732.     BYTE  AceFlags;
  2733.     WORD   AceSize;
  2734. } ACE_HEADER;
  2735. typedef ACE_HEADER *PACE_HEADER;
  2736.  
  2737. //
  2738. //  The following are the predefined ace types that go into the AceType
  2739. //  field of an Ace header.
  2740. //
  2741.  
  2742. #define ACCESS_ALLOWED_ACE_TYPE          (0x0)
  2743. #define ACCESS_DENIED_ACE_TYPE           (0x1)
  2744. #define SYSTEM_AUDIT_ACE_TYPE            (0x2)
  2745. #define SYSTEM_ALARM_ACE_TYPE            (0x3)
  2746.  
  2747. //
  2748. //  The following are the inherit flags that go into the AceFlags field
  2749. //  of an Ace header.
  2750. //
  2751.  
  2752. #define OBJECT_INHERIT_ACE                (0x1)
  2753. #define CONTAINER_INHERIT_ACE             (0x2)
  2754. #define NO_PROPAGATE_INHERIT_ACE          (0x4)
  2755. #define INHERIT_ONLY_ACE                  (0x8)
  2756. #define VALID_INHERIT_FLAGS               (0xF)
  2757.  
  2758.  
  2759. //  The following are the currently defined ACE flags that go into the
  2760. //  AceFlags field of an ACE header.  Each ACE type has its own set of
  2761. //  AceFlags.
  2762. //
  2763. //  SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  2764. //  types to indicate that a message is generated for successful accesses.
  2765. //
  2766. //  FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  2767. //  to indicate that a message is generated for failed accesses.
  2768. //
  2769.  
  2770. //
  2771. //  SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  2772. //
  2773. //  These control the signaling of audit and alarms for success or failure.
  2774. //
  2775.  
  2776. #define SUCCESSFUL_ACCESS_ACE_FLAG       (0x40)
  2777. #define FAILED_ACCESS_ACE_FLAG           (0x80)
  2778.  
  2779.  
  2780. //
  2781. //  We'll define the structure of the predefined ACE types.  Pictorally
  2782. //  the structure of the predefined ACE's is as follows:
  2783. //
  2784. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2785. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  2786. //      +---------------+-------+-------+---------------+---------------+
  2787. //      |    AceFlags   | Resd  |Inherit|    AceSize    |     AceType   |
  2788. //      +---------------+-------+-------+---------------+---------------+
  2789. //      |                              Mask                             |
  2790. //      +---------------------------------------------------------------+
  2791. //      |                                                               |
  2792. //      +                                                               +
  2793. //      |                                                               |
  2794. //      +                              Sid                              +
  2795. //      |                                                               |
  2796. //      +                                                               +
  2797. //      |                                                               |
  2798. //      +---------------------------------------------------------------+
  2799. //
  2800. //  Mask is the access mask associated with the ACE.  This is either the
  2801. //  access allowed, access denied, audit, or alarm mask.
  2802. //
  2803. //  Sid is the Sid associated with the ACE.
  2804. //
  2805.  
  2806. //  The following are the four predefined ACE types.
  2807.  
  2808. //  Examine the AceType field in the Header to determine
  2809. //  which structure is appropriate to use for casting.
  2810.  
  2811.  
  2812. typedef struct _ACCESS_ALLOWED_ACE {
  2813.     ACE_HEADER Header;
  2814.     ACCESS_MASK Mask;
  2815.     DWORD SidStart;
  2816. } ACCESS_ALLOWED_ACE;
  2817.  
  2818. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  2819.  
  2820. typedef struct _ACCESS_DENIED_ACE {
  2821.     ACE_HEADER Header;
  2822.     ACCESS_MASK Mask;
  2823.     DWORD SidStart;
  2824. } ACCESS_DENIED_ACE;
  2825. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  2826.  
  2827. typedef struct _SYSTEM_AUDIT_ACE {
  2828.     ACE_HEADER Header;
  2829.     ACCESS_MASK Mask;
  2830.     DWORD SidStart;
  2831. } SYSTEM_AUDIT_ACE;
  2832. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  2833.  
  2834. typedef struct _SYSTEM_ALARM_ACE {
  2835.     ACE_HEADER Header;
  2836.     ACCESS_MASK Mask;
  2837.     DWORD SidStart;
  2838. } SYSTEM_ALARM_ACE;
  2839. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  2840.  
  2841. // end_ntifs
  2842.  
  2843.  
  2844.  
  2845. //
  2846. //  The following declarations are used for setting and querying information
  2847. //  about and ACL.  First are the various information classes available to
  2848. //  the user.
  2849. //
  2850.  
  2851. typedef enum _ACL_INFORMATION_CLASS {
  2852.     AclRevisionInformation = 1,
  2853.     AclSizeInformation
  2854. } ACL_INFORMATION_CLASS;
  2855.  
  2856. //
  2857. //  This record is returned/sent if the user is requesting/setting the
  2858. //  AclRevisionInformation
  2859. //
  2860.  
  2861. typedef struct _ACL_REVISION_INFORMATION {
  2862.     DWORD AclRevision;
  2863. } ACL_REVISION_INFORMATION;
  2864. typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION;
  2865.  
  2866. //
  2867. //  This record is returned if the user is requesting AclSizeInformation
  2868. //
  2869.  
  2870. typedef struct _ACL_SIZE_INFORMATION {
  2871.     DWORD AceCount;
  2872.     DWORD AclBytesInUse;
  2873.     DWORD AclBytesFree;
  2874. } ACL_SIZE_INFORMATION;
  2875. typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION;
  2876.  
  2877.  
  2878. ////////////////////////////////////////////////////////////////////////
  2879. //                                                                    //
  2880. //                             SECURITY_DESCRIPTOR                    //
  2881. //                                                                    //
  2882. ////////////////////////////////////////////////////////////////////////
  2883. //
  2884. //  Define the Security Descriptor and related data types.
  2885. //  This is an opaque data structure.
  2886. //
  2887.  
  2888. // begin_ntddk begin_ntifs
  2889. //
  2890. // Current security descriptor revision value
  2891. //
  2892.  
  2893. #define SECURITY_DESCRIPTOR_REVISION     (1)
  2894. #define SECURITY_DESCRIPTOR_REVISION1    (1)
  2895.  
  2896. // end_ntddk
  2897.  
  2898. //
  2899. // Minimum length, in bytes, needed to build a security descriptor
  2900. // (NOTE: This must manually be kept consistent with the)
  2901. // (sizeof(SECURITY_DESCRIPTOR)                         )
  2902. //
  2903.  
  2904. #define SECURITY_DESCRIPTOR_MIN_LENGTH   (20)
  2905.  
  2906.  
  2907. typedef WORD   SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  2908.  
  2909. #define SE_OWNER_DEFAULTED               (0x0001)
  2910. #define SE_GROUP_DEFAULTED               (0x0002)
  2911. #define SE_DACL_PRESENT                  (0x0004)
  2912. #define SE_DACL_DEFAULTED                (0x0008)
  2913. #define SE_SACL_PRESENT                  (0x0010)
  2914. #define SE_SACL_DEFAULTED                (0x0020)
  2915. #define SE_SELF_RELATIVE                 (0x8000)
  2916.  
  2917. //
  2918. //  Where:
  2919. //
  2920. //      SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  2921. //          SID pointed to by the Owner field was provided by a
  2922. //          defaulting mechanism rather than explicitly provided by the
  2923. //          original provider of the security descriptor.  This may
  2924. //          affect the treatment of the SID with respect to inheritence
  2925. //          of an owner.
  2926. //
  2927. //      SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  2928. //          SID in the Group field was provided by a defaulting mechanism
  2929. //          rather than explicitly provided by the original provider of
  2930. //          the security descriptor.  This may affect the treatment of
  2931. //          the SID with respect to inheritence of a primary group.
  2932. //
  2933. //      SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  2934. //          security descriptor contains a discretionary ACL.  If this
  2935. //          flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  2936. //          null, then a null ACL is explicitly being specified.
  2937. //
  2938. //      SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  2939. //          ACL pointed to by the Dacl field was provided by a defaulting
  2940. //          mechanism rather than explicitly provided by the original
  2941. //          provider of the security descriptor.  This may affect the
  2942. //          treatment of the ACL with respect to inheritence of an ACL.
  2943. //          This flag is ignored if the DaclPresent flag is not set.
  2944. //
  2945. //      SE_SACL_PRESENT - This boolean flag, when set,  indicates that the
  2946. //          security descriptor contains a system ACL pointed to by the
  2947. //          Sacl field.  If this flag is set and the Sacl field of the
  2948. //          SECURITY_DESCRIPTOR is null, then an empty (but present)
  2949. //          ACL is being specified.
  2950. //
  2951. //      SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  2952. //          ACL pointed to by the Sacl field was provided by a defaulting
  2953. //          mechanism rather than explicitly provided by the original
  2954. //          provider of the security descriptor.  This may affect the
  2955. //          treatment of the ACL with respect to inheritence of an ACL.
  2956. //          This flag is ignored if the SaclPresent flag is not set.
  2957. //
  2958. //      SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  2959. //          security descriptor is in self-relative form.  In this form,
  2960. //          all fields of the security descriptor are contiguous in memory
  2961. //          and all pointer fields are expressed as offsets from the
  2962. //          beginning of the security descriptor.  This form is useful
  2963. //          for treating security descriptors as opaque data structures
  2964. //          for transmission in communication protocol or for storage on
  2965. //          secondary media.
  2966. //
  2967. //
  2968. //
  2969. // Pictorially the structure of a security descriptor is as follows:
  2970. //
  2971. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2972. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  2973. //      +---------------------------------------------------------------+
  2974. //      |            Control            |Reserved1 (SBZ)|   Revision    |
  2975. //      +---------------------------------------------------------------+
  2976. //      |                            Owner                              |
  2977. //      +---------------------------------------------------------------+
  2978. //      |                            Group                              |
  2979. //      +---------------------------------------------------------------+
  2980. //      |                            Sacl                               |
  2981. //      +---------------------------------------------------------------+
  2982. //      |                            Dacl                               |
  2983. //      +---------------------------------------------------------------+
  2984. //
  2985. // In general, this data structure should be treated opaquely to ensure future
  2986. // compatibility.
  2987. //
  2988. //
  2989.  
  2990. typedef struct _SECURITY_DESCRIPTOR {
  2991.    BYTE  Revision;
  2992.    BYTE  Sbz1;
  2993.    SECURITY_DESCRIPTOR_CONTROL Control;
  2994.    PSID Owner;
  2995.    PSID Group;
  2996.    PACL Sacl;
  2997.    PACL Dacl;
  2998.    } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  2999.  
  3000. // end_ntifs
  3001.  
  3002. // Where:
  3003. //
  3004. //     Revision - Contains the revision level of the security
  3005. //         descriptor.  This allows this structure to be passed between
  3006. //         systems or stored on disk even though it is expected to
  3007. //         change in the future.
  3008. //
  3009. //     Control - A set of flags which qualify the meaning of the
  3010. //         security descriptor or individual fields of the security
  3011. //         descriptor.
  3012. //
  3013. //     Owner - is a pointer to an SID representing an object's owner.
  3014. //         If this field is null, then no owner SID is present in the
  3015. //         security descriptor.  If the security descriptor is in
  3016. //         self-relative form, then this field contains an offset to
  3017. //         the SID, rather than a pointer.
  3018. //
  3019. //     Group - is a pointer to an SID representing an object's primary
  3020. //         group.  If this field is null, then no primary group SID is
  3021. //         present in the security descriptor.  If the security descriptor
  3022. //         is in self-relative form, then this field contains an offset to
  3023. //         the SID, rather than a pointer.
  3024. //
  3025. //     Sacl - is a pointer to a system ACL.  This field value is only
  3026. //         valid if the DaclPresent control flag is set.  If the
  3027. //         SaclPresent flag is set and this field is null, then a null
  3028. //         ACL  is specified.  If the security descriptor is in
  3029. //         self-relative form, then this field contains an offset to
  3030. //         the ACL, rather than a pointer.
  3031. //
  3032. //     Dacl - is a pointer to a discretionary ACL.  This field value is
  3033. //         only valid if the DaclPresent control flag is set.  If the
  3034. //         DaclPresent flag is set and this field is null, then a null
  3035. //         ACL (unconditionally granting access) is specified.  If the
  3036. //         security descriptor is in self-relative form, then this field
  3037. //         contains an offset to the ACL, rather than a pointer.
  3038. //
  3039.  
  3040.  
  3041.  
  3042. ////////////////////////////////////////////////////////////////////////
  3043. //                                                                    //
  3044. //               Privilege Related Data Structures                    //
  3045. //                                                                    //
  3046. ////////////////////////////////////////////////////////////////////////
  3047.  
  3048.  
  3049. // begin_ntddk begin_nthal begin_ntifs
  3050. //
  3051. // Privilege attributes
  3052. //
  3053.  
  3054. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  3055. #define SE_PRIVILEGE_ENABLED            (0x00000002L)
  3056. #define SE_PRIVILEGE_USED_FOR_ACCESS    (0x80000000L)
  3057.  
  3058. //
  3059. // Privilege Set Control flags
  3060. //
  3061.  
  3062. #define PRIVILEGE_SET_ALL_NECESSARY    (1)
  3063.  
  3064. //
  3065. //  Privilege Set - This is defined for a privilege set of one.
  3066. //                  If more than one privilege is needed, then this structure
  3067. //                  will need to be allocated with more space.
  3068. //
  3069. //  Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  3070. //  structure (defined in se.h)
  3071. //
  3072.  
  3073. typedef struct _PRIVILEGE_SET {
  3074.     DWORD PrivilegeCount;
  3075.     DWORD Control;
  3076.     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  3077.     } PRIVILEGE_SET, * PPRIVILEGE_SET;
  3078.  
  3079.  
  3080. ////////////////////////////////////////////////////////////////////////
  3081. //                                                                    //
  3082. //               NT Defined Privileges                                //
  3083. //                                                                    //
  3084. ////////////////////////////////////////////////////////////////////////
  3085.  
  3086. #define SE_CREATE_TOKEN_NAME              TEXT("SeCreateTokenPrivilege")
  3087. #define SE_ASSIGNPRIMARYTOKEN_NAME        TEXT("SeAssignPrimaryTokenPrivilege")
  3088. #define SE_LOCK_MEMORY_NAME               TEXT("SeLockMemoryPrivilege")
  3089. #define SE_INCREASE_QUOTA_NAME            TEXT("SeIncreaseQuotaPrivilege")
  3090. #define SE_UNSOLICITED_INPUT_NAME         TEXT("SeUnsolicitedInputPrivilege")
  3091. #define SE_MACHINE_ACCOUNT_NAME           TEXT("SeMachineAccountPrivilege")
  3092. #define SE_TCB_NAME                       TEXT("SeTcbPrivilege")
  3093. #define SE_SECURITY_NAME                  TEXT("SeSecurityPrivilege")
  3094. #define SE_TAKE_OWNERSHIP_NAME            TEXT("SeTakeOwnershipPrivilege")
  3095. #define SE_LOAD_DRIVER_NAME               TEXT("SeLoadDriverPrivilege")
  3096. #define SE_SYSTEM_PROFILE_NAME            TEXT("SeSystemProfilePrivilege")
  3097. #define SE_SYSTEMTIME_NAME                TEXT("SeSystemtimePrivilege")
  3098. #define SE_PROF_SINGLE_PROCESS_NAME       TEXT("SeProfileSingleProcessPrivilege")
  3099. #define SE_INC_BASE_PRIORITY_NAME         TEXT("SeIncreaseBasePriorityPrivilege")
  3100. #define SE_CREATE_PAGEFILE_NAME           TEXT("SeCreatePagefilePrivilege")
  3101. #define SE_CREATE_PERMANENT_NAME          TEXT("SeCreatePermanentPrivilege")
  3102. #define SE_BACKUP_NAME                    TEXT("SeBackupPrivilege")
  3103. #define SE_RESTORE_NAME                   TEXT("SeRestorePrivilege")
  3104. #define SE_SHUTDOWN_NAME                  TEXT("SeShutdownPrivilege")
  3105. #define SE_DEBUG_NAME                     TEXT("SeDebugPrivilege")
  3106. #define SE_AUDIT_NAME                     TEXT("SeAuditPrivilege")
  3107. #define SE_SYSTEM_ENVIRONMENT_NAME        TEXT("SeSystemEnvironmentPrivilege")
  3108. #define SE_CHANGE_NOTIFY_NAME             TEXT("SeChangeNotifyPrivilege")
  3109. #define SE_REMOTE_SHUTDOWN_NAME           TEXT("SeRemoteShutdownPrivilege")
  3110.  
  3111.  
  3112. ////////////////////////////////////////////////////////////////////
  3113. //                                                                //
  3114. //           Security Quality Of Service                          //
  3115. //                                                                //
  3116. //                                                                //
  3117. ////////////////////////////////////////////////////////////////////
  3118.  
  3119. // begin_ntddk begin_nthal begin_ntifs
  3120. //
  3121. // Impersonation Level
  3122. //
  3123. // Impersonation level is represented by a pair of bits in Windows.
  3124. // If a new impersonation level is added or lowest value is changed from
  3125. // 0 to something else, fix the Windows CreateFile call.
  3126. //
  3127.  
  3128. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  3129.     SecurityAnonymous,
  3130.     SecurityIdentification,
  3131.     SecurityImpersonation,
  3132.     SecurityDelegation
  3133.     } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  3134.  
  3135. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  3136.  
  3137. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  3138.  
  3139.  
  3140. ////////////////////////////////////////////////////////////////////
  3141. //                                                                //
  3142. //           Token Object Definitions                             //
  3143. //                                                                //
  3144. //                                                                //
  3145. ////////////////////////////////////////////////////////////////////
  3146.  
  3147.  
  3148. //
  3149. // Token Specific Access Rights.
  3150. //
  3151.  
  3152. #define TOKEN_ASSIGN_PRIMARY    (0x0001)
  3153. #define TOKEN_DUPLICATE         (0x0002)
  3154. #define TOKEN_IMPERSONATE       (0x0004)
  3155. #define TOKEN_QUERY             (0x0008)
  3156. #define TOKEN_QUERY_SOURCE      (0x0010)
  3157. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  3158. #define TOKEN_ADJUST_GROUPS     (0x0040)
  3159. #define TOKEN_ADJUST_DEFAULT    (0x0080)
  3160.  
  3161. #define TOKEN_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED  |\
  3162.                           TOKEN_ASSIGN_PRIMARY      |\
  3163.                           TOKEN_DUPLICATE           |\
  3164.                           TOKEN_IMPERSONATE         |\
  3165.                           TOKEN_QUERY               |\
  3166.                           TOKEN_QUERY_SOURCE        |\
  3167.                           TOKEN_ADJUST_PRIVILEGES   |\
  3168.                           TOKEN_ADJUST_GROUPS       |\
  3169.                           TOKEN_ADJUST_DEFAULT)
  3170.  
  3171.  
  3172. #define TOKEN_READ       (STANDARD_RIGHTS_READ      |\
  3173.                           TOKEN_QUERY)
  3174.  
  3175.  
  3176. #define TOKEN_WRITE      (STANDARD_RIGHTS_WRITE     |\
  3177.                           TOKEN_ADJUST_PRIVILEGES   |\
  3178.                           TOKEN_ADJUST_GROUPS       |\
  3179.                           TOKEN_ADJUST_DEFAULT)
  3180.  
  3181. #define TOKEN_EXECUTE    (STANDARD_RIGHTS_EXECUTE)
  3182.  
  3183.  
  3184. //
  3185. //
  3186. // Token Types
  3187. //
  3188.  
  3189. typedef enum _TOKEN_TYPE {
  3190.     TokenPrimary = 1,
  3191.     TokenImpersonation
  3192.     } TOKEN_TYPE;
  3193. typedef TOKEN_TYPE *PTOKEN_TYPE;
  3194.  
  3195.  
  3196. //
  3197. // Token Information Classes.
  3198. //
  3199.  
  3200.  
  3201. typedef enum _TOKEN_INFORMATION_CLASS {
  3202.     TokenUser = 1,
  3203.     TokenGroups,
  3204.     TokenPrivileges,
  3205.     TokenOwner,
  3206.     TokenPrimaryGroup,
  3207.     TokenDefaultDacl,
  3208.     TokenSource,
  3209.     TokenType,
  3210.     TokenImpersonationLevel,
  3211.     TokenStatistics
  3212. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  3213. // end_ntifs
  3214.  
  3215. //
  3216. // Token information class structures
  3217. //
  3218.  
  3219.  
  3220. typedef struct _TOKEN_USER {
  3221.     SID_AND_ATTRIBUTES User;
  3222. } TOKEN_USER, *PTOKEN_USER;
  3223.  
  3224. // begin_ntifs
  3225.  
  3226. typedef struct _TOKEN_GROUPS {
  3227.     DWORD GroupCount;
  3228.     SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  3229. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  3230.  
  3231.  
  3232. typedef struct _TOKEN_PRIVILEGES {
  3233.     DWORD PrivilegeCount;
  3234.     LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  3235. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  3236.  
  3237. // end_ntifs
  3238.  
  3239. typedef struct _TOKEN_OWNER {
  3240.     PSID Owner;
  3241. } TOKEN_OWNER, *PTOKEN_OWNER;
  3242.  
  3243.  
  3244. typedef struct _TOKEN_PRIMARY_GROUP {
  3245.     PSID PrimaryGroup;
  3246. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  3247.  
  3248.  
  3249. typedef struct _TOKEN_DEFAULT_DACL {
  3250.     PACL DefaultDacl;
  3251. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  3252.  
  3253.  
  3254.  
  3255. #define TOKEN_SOURCE_LENGTH 8
  3256.  
  3257. typedef struct _TOKEN_SOURCE {
  3258.     CHAR SourceName[TOKEN_SOURCE_LENGTH];
  3259.     LUID SourceIdentifier;
  3260. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  3261.  
  3262. // end_ntifs
  3263.  
  3264. typedef struct _TOKEN_STATISTICS {
  3265.     LUID TokenId;
  3266.     LUID AuthenticationId;
  3267.     LARGE_INTEGER ExpirationTime;
  3268.     TOKEN_TYPE TokenType;
  3269.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  3270.     DWORD DynamicCharged;
  3271.     DWORD DynamicAvailable;
  3272.     DWORD GroupCount;
  3273.     DWORD PrivilegeCount;
  3274.     LUID ModifiedId;
  3275. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  3276.  
  3277.  
  3278. // begin_ntifs
  3279.  
  3280. typedef struct _TOKEN_CONTROL {
  3281.     LUID TokenId;
  3282.     LUID AuthenticationId;
  3283.     LUID ModifiedId;
  3284.     TOKEN_SOURCE TokenSource;
  3285.     } TOKEN_CONTROL, *PTOKEN_CONTROL;
  3286.  
  3287. //
  3288. // Security Tracking Mode
  3289. //
  3290.  
  3291. #define SECURITY_DYNAMIC_TRACKING      (TRUE)
  3292. #define SECURITY_STATIC_TRACKING       (FALSE)
  3293.  
  3294. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  3295.                     * PSECURITY_CONTEXT_TRACKING_MODE;
  3296.  
  3297.  
  3298.  
  3299. //
  3300. // Quality Of Service
  3301. //
  3302.  
  3303. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  3304.     DWORD Length;
  3305.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  3306.     SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  3307.     BOOLEAN EffectiveOnly;
  3308.     } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  3309.  
  3310.  
  3311. //
  3312. // Used to represent information related to a thread impersonation
  3313. //
  3314.  
  3315. typedef struct _SE_IMPERSONATION_STATE {
  3316.     PACCESS_TOKEN Token;
  3317.     BOOLEAN CopyOnOpen;
  3318.     BOOLEAN EffectiveOnly;
  3319.     SECURITY_IMPERSONATION_LEVEL Level;
  3320. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  3321.  
  3322.  
  3323. typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  3324.  
  3325. #define OWNER_SECURITY_INFORMATION       (0X00000001L)
  3326. #define GROUP_SECURITY_INFORMATION       (0X00000002L)
  3327. #define DACL_SECURITY_INFORMATION        (0X00000004L)
  3328. #define SACL_SECURITY_INFORMATION        (0X00000008L)
  3329.  
  3330.  
  3331. //
  3332. // Image Format
  3333. //
  3334.  
  3335. #include "pshpack4.h"                   // 4 byte packing is the default
  3336.  
  3337. #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
  3338. #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
  3339. #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
  3340. #define IMAGE_VXD_SIGNATURE                 0x454C      // LE
  3341. #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
  3342.  
  3343. #include "pshpack2.h"                   // 16 bit headers are 2 byte packed
  3344.  
  3345. typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
  3346.     WORD   e_magic;                     // Magic number
  3347.     WORD   e_cblp;                      // Bytes on last page of file
  3348.     WORD   e_cp;                        // Pages in file
  3349.     WORD   e_crlc;                      // Relocations
  3350.     WORD   e_cparhdr;                   // Size of header in paragraphs
  3351.     WORD   e_minalloc;                  // Minimum extra paragraphs needed
  3352.     WORD   e_maxalloc;                  // Maximum extra paragraphs needed
  3353.     WORD   e_ss;                        // Initial (relative) SS value
  3354.     WORD   e_sp;                        // Initial SP value
  3355.     WORD   e_csum;                      // Checksum
  3356.     WORD   e_ip;                        // Initial IP value
  3357.     WORD   e_cs;                        // Initial (relative) CS value
  3358.     WORD   e_lfarlc;                    // File address of relocation table
  3359.     WORD   e_ovno;                      // Overlay number
  3360.     WORD   e_res[4];                    // Reserved words
  3361.     WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
  3362.     WORD   e_oeminfo;                   // OEM information; e_oemid specific
  3363.     WORD   e_res2[10];                  // Reserved words
  3364.     LONG   e_lfanew;                    // File address of new exe header
  3365.   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  3366.  
  3367. typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
  3368.     WORD   ne_magic;                    // Magic number
  3369.     CHAR   ne_ver;                      // Version number
  3370.     CHAR   ne_rev;                      // Revision number
  3371.     WORD   ne_enttab;                   // Offset of Entry Table
  3372.     WORD   ne_cbenttab;                 // Number of bytes in Entry Table
  3373.     LONG   ne_crc;                      // Checksum of whole file
  3374.     WORD   ne_flags;                    // Flag word
  3375.     WORD   ne_autodata;                 // Automatic data segment number
  3376.     WORD   ne_heap;                     // Initial heap allocation
  3377.     WORD   ne_stack;                    // Initial stack allocation
  3378.     LONG   ne_csip;                     // Initial CS:IP setting
  3379.     LONG   ne_sssp;                     // Initial SS:SP setting
  3380.     WORD   ne_cseg;                     // Count of file segments
  3381.     WORD   ne_cmod;                     // Entries in Module Reference Table
  3382.     WORD   ne_cbnrestab;                // Size of non-resident name table
  3383.     WORD   ne_segtab;                   // Offset of Segment Table
  3384.     WORD   ne_rsrctab;                  // Offset of Resource Table
  3385.     WORD   ne_restab;                   // Offset of resident name table
  3386.     WORD   ne_modtab;                   // Offset of Module Reference Table
  3387.     WORD   ne_imptab;                   // Offset of Imported Names Table
  3388.     LONG   ne_nrestab;                  // Offset of Non-resident Names Table
  3389.     WORD   ne_cmovent;                  // Count of movable entries
  3390.     WORD   ne_align;                    // Segment alignment shift count
  3391.     WORD   ne_cres;                     // Count of resource segments
  3392.     BYTE   ne_exetyp;                   // Target Operating system
  3393.     BYTE   ne_flagsothers;              // Other .EXE flags
  3394.     WORD   ne_pretthunks;               // offset to return thunks
  3395.     WORD   ne_psegrefbytes;             // offset to segment ref. bytes
  3396.     WORD   ne_swaparea;                 // Minimum code swap area size
  3397.     WORD   ne_expver;                   // Expected Windows version number
  3398.   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  3399.  
  3400. typedef struct _IMAGE_VXD_HEADER {      // Windows VXD header
  3401.     WORD   e32_magic;                   // Magic number
  3402.     BYTE   e32_border;                  // The byte ordering for the VXD
  3403.     BYTE   e32_worder;                  // The word ordering for the VXD
  3404.     DWORD  e32_level;                   // The EXE format level for now = 0
  3405.     WORD   e32_cpu;                     // The CPU type
  3406.     WORD   e32_os;                      // The OS type
  3407.     DWORD  e32_ver;                     // Module version
  3408.     DWORD  e32_mflags;                  // Module flags
  3409.     DWORD  e32_mpages;                  // Module # pages
  3410.     DWORD  e32_startobj;                // Object # for instruction pointer
  3411.     DWORD  e32_eip;                     // Extended instruction pointer
  3412.     DWORD  e32_stackobj;                // Object # for stack pointer
  3413.     DWORD  e32_esp;                     // Extended stack pointer
  3414.     DWORD  e32_pagesize;                // VXD page size
  3415.     DWORD  e32_lastpagesize;            // Last page size in VXD
  3416.     DWORD  e32_fixupsize;               // Fixup section size
  3417.     DWORD  e32_fixupsum;                // Fixup section checksum
  3418.     DWORD  e32_ldrsize;                 // Loader section size
  3419.     DWORD  e32_ldrsum;                  // Loader section checksum
  3420.     DWORD  e32_objtab;                  // Object table offset
  3421.     DWORD  e32_objcnt;                  // Number of objects in module
  3422.     DWORD  e32_objmap;                  // Object page map offset
  3423.     DWORD  e32_itermap;                 // Object iterated data map offset
  3424.     DWORD  e32_rsrctab;                 // Offset of Resource Table
  3425.     DWORD  e32_rsrccnt;                 // Number of resource entries
  3426.     DWORD  e32_restab;                  // Offset of resident name table
  3427.     DWORD  e32_enttab;                  // Offset of Entry Table
  3428.     DWORD  e32_dirtab;                  // Offset of Module Directive Table
  3429.     DWORD  e32_dircnt;                  // Number of module directives
  3430.     DWORD  e32_fpagetab;                // Offset of Fixup Page Table
  3431.     DWORD  e32_frectab;                 // Offset of Fixup Record Table
  3432.     DWORD  e32_impmod;                  // Offset of Import Module Name Table
  3433.     DWORD  e32_impmodcnt;               // Number of entries in Import Module Name Table
  3434.     DWORD  e32_impproc;                 // Offset of Import Procedure Name Table
  3435.     DWORD  e32_pagesum;                 // Offset of Per-Page Checksum Table
  3436.     DWORD  e32_datapage;                // Offset of Enumerated Data Pages
  3437.     DWORD  e32_preload;                 // Number of preload pages
  3438.     DWORD  e32_nrestab;                 // Offset of Non-resident Names Table
  3439.     DWORD  e32_cbnrestab;               // Size of Non-resident Name Table
  3440.     DWORD  e32_nressum;                 // Non-resident Name Table Checksum
  3441.     DWORD  e32_autodata;                // Object # for automatic data object
  3442.     DWORD  e32_debuginfo;               // Offset of the debugging information
  3443.     DWORD  e32_debuglen;                // The length of the debugging info. in bytes
  3444.     DWORD  e32_instpreload;             // Number of instance pages in preload section of VXD file
  3445.     DWORD  e32_instdemand;              // Number of instance pages in demand load section of VXD file
  3446.     DWORD  e32_heapsize;                // Size of heap - for 16-bit apps
  3447.     BYTE   e32_res3[12];                // Reserved words
  3448.     DWORD  e32_winresoff;
  3449.     DWORD  e32_winreslen;
  3450.     WORD   e32_devid;                   // Device ID for VxD
  3451.     WORD   e32_ddkver;                  // DDK version for VxD
  3452.   } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
  3453.  
  3454. #include "poppack.h"                    // Back to 4 byte packing
  3455.  
  3456. //
  3457. // File header format.
  3458. //
  3459.  
  3460. typedef struct _IMAGE_FILE_HEADER {
  3461.     WORD    Machine;
  3462.     WORD    NumberOfSections;
  3463.     DWORD   TimeDateStamp;
  3464.     DWORD   PointerToSymbolTable;
  3465.     DWORD   NumberOfSymbols;
  3466.     WORD    SizeOfOptionalHeader;
  3467.     WORD    Characteristics;
  3468. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  3469.  
  3470. #define IMAGE_SIZEOF_FILE_HEADER             20
  3471.  
  3472. #define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
  3473. #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
  3474. #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
  3475. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
  3476. #define IMAGE_FILE_AGGRESIVE_WS_TRIM         0x0010  // Agressively trim working set
  3477. #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
  3478. #define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
  3479. #define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
  3480. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400  // If Image is on removable media, copy and run from the swap file.
  3481. #define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800  // If Image is on Net, copy and run from the swap file.
  3482. #define IMAGE_FILE_SYSTEM                    0x1000  // System File.
  3483. #define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
  3484. #define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000  // File should only be run on a UP machine
  3485. #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
  3486.  
  3487. #define IMAGE_FILE_MACHINE_UNKNOWN           0
  3488. #define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
  3489. #define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0x160 big-endian
  3490. #define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
  3491. #define IMAGE_FILE_MACHINE_R10000            0x168   // MIPS little-endian
  3492. #define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
  3493. #define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
  3494.  
  3495. //
  3496. // Directory format.
  3497. //
  3498.  
  3499. typedef struct _IMAGE_DATA_DIRECTORY {
  3500.     DWORD   VirtualAddress;
  3501.     DWORD   Size;
  3502. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  3503.  
  3504. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
  3505.  
  3506. //
  3507. // Optional header format.
  3508. //
  3509.  
  3510. typedef struct _IMAGE_OPTIONAL_HEADER {
  3511.     //
  3512.     // Standard fields.
  3513.     //
  3514.  
  3515.     WORD    Magic;
  3516.     BYTE    MajorLinkerVersion;
  3517.     BYTE    MinorLinkerVersion;
  3518.     DWORD   SizeOfCode;
  3519.     DWORD   SizeOfInitializedData;
  3520.     DWORD   SizeOfUninitializedData;
  3521.     DWORD   AddressOfEntryPoint;
  3522.     DWORD   BaseOfCode;
  3523.     DWORD   BaseOfData;
  3524.  
  3525.     //
  3526.     // NT additional fields.
  3527.     //
  3528.  
  3529.     DWORD   ImageBase;
  3530.     DWORD   SectionAlignment;
  3531.     DWORD   FileAlignment;
  3532.     WORD    MajorOperatingSystemVersion;
  3533.     WORD    MinorOperatingSystemVersion;
  3534.     WORD    MajorImageVersion;
  3535.     WORD    MinorImageVersion;
  3536.     WORD    MajorSubsystemVersion;
  3537.     WORD    MinorSubsystemVersion;
  3538.     DWORD   Win32VersionValue;
  3539.     DWORD   SizeOfImage;
  3540.     DWORD   SizeOfHeaders;
  3541.     DWORD   CheckSum;
  3542.     WORD    Subsystem;
  3543.     WORD    DllCharacteristics;
  3544.     DWORD   SizeOfStackReserve;
  3545.     DWORD   SizeOfStackCommit;
  3546.     DWORD   SizeOfHeapReserve;
  3547.     DWORD   SizeOfHeapCommit;
  3548.     DWORD   LoaderFlags;
  3549.     DWORD   NumberOfRvaAndSizes;
  3550.     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  3551. } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
  3552.  
  3553. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  3554.     WORD   Magic;
  3555.     BYTE   MajorLinkerVersion;
  3556.     BYTE   MinorLinkerVersion;
  3557.     DWORD  SizeOfCode;
  3558.     DWORD  SizeOfInitializedData;
  3559.     DWORD  SizeOfUninitializedData;
  3560.     DWORD  AddressOfEntryPoint;
  3561.     DWORD  BaseOfCode;
  3562.     DWORD  BaseOfData;
  3563.     DWORD  BaseOfBss;
  3564.     DWORD  GprMask;
  3565.     DWORD  CprMask[4];
  3566.     DWORD  GpValue;
  3567. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  3568.  
  3569. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
  3570. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
  3571. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
  3572.  
  3573. #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
  3574. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
  3575.  
  3576. typedef struct _IMAGE_NT_HEADERS {
  3577.     DWORD Signature;
  3578.     IMAGE_FILE_HEADER FileHeader;
  3579.     IMAGE_OPTIONAL_HEADER OptionalHeader;
  3580. } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
  3581.  
  3582. typedef struct _IMAGE_ROM_HEADERS {
  3583.     IMAGE_FILE_HEADER FileHeader;
  3584.     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  3585. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  3586.  
  3587. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
  3588.     ((DWORD)ntheader +                                                  \
  3589.      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
  3590.      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
  3591.     ))
  3592.  
  3593.  
  3594. // Subsystem Values
  3595.  
  3596. #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
  3597. #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
  3598. #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
  3599. #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
  3600. #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
  3601. #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
  3602. #define IMAGE_SUBSYSTEM_RESERVED8            8   // image run  in the 8 subsystem.
  3603.  
  3604.  
  3605. // Directory Entries
  3606.  
  3607. #define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
  3608. #define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
  3609. #define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
  3610. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
  3611. #define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
  3612. #define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
  3613. #define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
  3614. #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
  3615. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
  3616. #define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
  3617. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
  3618. #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  11   // Bound Import Directory in headers
  3619. #define IMAGE_DIRECTORY_ENTRY_IAT           12   // Import Address Table
  3620.  
  3621. //
  3622. // Section header format.
  3623. //
  3624.  
  3625. #define IMAGE_SIZEOF_SHORT_NAME              8
  3626.  
  3627. typedef struct _IMAGE_SECTION_HEADER {
  3628.     BYTE    Name[IMAGE_SIZEOF_SHORT_NAME];
  3629.     union {
  3630.             DWORD   PhysicalAddress;
  3631.             DWORD   VirtualSize;
  3632.     } Misc;
  3633.     DWORD   VirtualAddress;
  3634.     DWORD   SizeOfRawData;
  3635.     DWORD   PointerToRawData;
  3636.     DWORD   PointerToRelocations;
  3637.     DWORD   PointerToLinenumbers;
  3638.     WORD    NumberOfRelocations;
  3639.     WORD    NumberOfLinenumbers;
  3640.     DWORD   Characteristics;
  3641. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  3642.  
  3643. #define IMAGE_SIZEOF_SECTION_HEADER          40
  3644.  
  3645. //
  3646. // Section characteristics.
  3647. //
  3648.  
  3649. //      IMAGE_SCN_TYPE_REG                   0x00000000  // Reserved.
  3650. //      IMAGE_SCN_TYPE_DSECT                 0x00000001  // Reserved.
  3651. //      IMAGE_SCN_TYPE_NOLOAD                0x00000002  // Reserved.
  3652. //      IMAGE_SCN_TYPE_GROUP                 0x00000004  // Reserved.
  3653. #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
  3654. //      IMAGE_SCN_TYPE_COPY                  0x00000010  // Reserved.
  3655.  
  3656. #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
  3657. #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
  3658. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
  3659.  
  3660. #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
  3661. #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
  3662. //      IMAGE_SCN_TYPE_OVER                  0x00000400  // Reserved.
  3663. #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
  3664. #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
  3665. //                                           0x00002000  // Reserved.
  3666.  
  3667. //      IMAGE_SCN_MEM_PROTECTED - Obsolete   0x00004000
  3668. #define IMAGE_SCN_MEM_FARDATA                0x00008000
  3669. //      IMAGE_SCN_MEM_SYSHEAP  - Obsolete    0x00010000
  3670. #define IMAGE_SCN_MEM_PURGEABLE              0x00020000
  3671. #define IMAGE_SCN_MEM_16BIT                  0x00020000
  3672. #define IMAGE_SCN_MEM_LOCKED                 0x00040000
  3673. #define IMAGE_SCN_MEM_PRELOAD                0x00080000
  3674.  
  3675. #define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
  3676. #define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
  3677. #define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
  3678. #define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
  3679. #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
  3680. #define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
  3681. #define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
  3682. // Unused                                    0x00800000
  3683.  
  3684. #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  // Section contains extended relocations.
  3685. #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
  3686. #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
  3687. #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
  3688. #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
  3689. #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
  3690. #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
  3691. #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
  3692.  
  3693.  
  3694. //
  3695. // TLS Chaacteristic Flags
  3696. //
  3697. #define IMAGE_SCN_SCALE_INDEX                0x00000001  // Tls index is scaled
  3698.  
  3699. #include "pshpack2.h"                       // Symbols, relocs, and linenumbers are 2 byte packed
  3700.  
  3701. //
  3702. // Symbol format.
  3703. //
  3704.  
  3705. typedef struct _IMAGE_SYMBOL {
  3706.     union {
  3707.         BYTE    ShortName[8];
  3708.         struct {
  3709.             DWORD   Short;     // if 0, use LongName
  3710.             DWORD   Long;      // offset into string table
  3711.         } Name;
  3712.         PBYTE   LongName[2];
  3713.     } N;
  3714.     DWORD   Value;
  3715.     SHORT   SectionNumber;
  3716.     WORD    Type;
  3717.     BYTE    StorageClass;
  3718.     BYTE    NumberOfAuxSymbols;
  3719. } IMAGE_SYMBOL;
  3720. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  3721.  
  3722.  
  3723. #define IMAGE_SIZEOF_SYMBOL                  18
  3724.  
  3725. //
  3726. // Section values.
  3727. //
  3728. // Symbols have a section number of the section in which they are
  3729. // defined. Otherwise, section numbers have the following meanings:
  3730. //
  3731.  
  3732. #define IMAGE_SYM_UNDEFINED           (SHORT)0          // Symbol is undefined or is common.
  3733. #define IMAGE_SYM_ABSOLUTE            (SHORT)-1         // Symbol is an absolute value.
  3734. #define IMAGE_SYM_DEBUG               (SHORT)-2         // Symbol is a special debug item.
  3735.  
  3736. //
  3737. // Type (fundamental) values.
  3738. //
  3739.  
  3740. #define IMAGE_SYM_TYPE_NULL                 0x0000  // no type.
  3741. #define IMAGE_SYM_TYPE_VOID                 0x0001  //
  3742. #define IMAGE_SYM_TYPE_CHAR                 0x0002  // type character.
  3743. #define IMAGE_SYM_TYPE_SHORT                0x0003  // type short integer.
  3744. #define IMAGE_SYM_TYPE_INT                  0x0004  //
  3745. #define IMAGE_SYM_TYPE_LONG                 0x0005  //
  3746. #define IMAGE_SYM_TYPE_FLOAT                0x0006  //
  3747. #define IMAGE_SYM_TYPE_DOUBLE               0x0007  //
  3748. #define IMAGE_SYM_TYPE_STRUCT               0x0008  //
  3749. #define IMAGE_SYM_TYPE_UNION                0x0009  //
  3750. #define IMAGE_SYM_TYPE_ENUM                 0x000A  // enumeration.
  3751. #define IMAGE_SYM_TYPE_MOE                  0x000B  // member of enumeration.
  3752. #define IMAGE_SYM_TYPE_BYTE                 0x000C  //
  3753. #define IMAGE_SYM_TYPE_WORD                 0x000D  //
  3754. #define IMAGE_SYM_TYPE_UINT                 0x000E  //
  3755. #define IMAGE_SYM_TYPE_DWORD                0x000F  //
  3756. #define IMAGE_SYM_TYPE_PCODE                0x8000  //
  3757.  
  3758. //
  3759. // Type (derived) values.
  3760. //
  3761.  
  3762. #define IMAGE_SYM_DTYPE_NULL                0       // no derived type.
  3763. #define IMAGE_SYM_DTYPE_POINTER             1       // pointer.
  3764. #define IMAGE_SYM_DTYPE_FUNCTION            2       // function.
  3765. #define IMAGE_SYM_DTYPE_ARRAY               3       // array.
  3766.  
  3767. //
  3768. // Storage classes.
  3769. //
  3770.  
  3771. #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
  3772. #define IMAGE_SYM_CLASS_NULL                0x0000
  3773. #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
  3774. #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
  3775. #define IMAGE_SYM_CLASS_STATIC              0x0003
  3776. #define IMAGE_SYM_CLASS_REGISTER            0x0004
  3777. #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
  3778. #define IMAGE_SYM_CLASS_LABEL               0x0006
  3779. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
  3780. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
  3781. #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
  3782. #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
  3783. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
  3784. #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
  3785. #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
  3786. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
  3787. #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
  3788. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
  3789. #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
  3790. #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
  3791.  
  3792. #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044  //
  3793.  
  3794. #define IMAGE_SYM_CLASS_BLOCK               0x0064
  3795. #define IMAGE_SYM_CLASS_FUNCTION            0x0065
  3796. #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
  3797. #define IMAGE_SYM_CLASS_FILE                0x0067
  3798. // new
  3799. #define IMAGE_SYM_CLASS_SECTION             0x0068
  3800. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
  3801.  
  3802. // type packing constants
  3803.  
  3804. #define N_BTMASK                            0x000F
  3805. #define N_TMASK                             0x0030
  3806. #define N_TMASK1                            0x00C0
  3807. #define N_TMASK2                            0x00F0
  3808. #define N_BTSHFT                            4
  3809. #define N_TSHIFT                            2
  3810.  
  3811. // MACROS
  3812.  
  3813. // Basic Type of  x
  3814. #define BTYPE(x) ((x) & N_BTMASK)
  3815.  
  3816. // Is x a pointer?
  3817. #ifndef ISPTR
  3818. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  3819. #endif
  3820.  
  3821. // Is x a function?
  3822. #ifndef ISFCN
  3823. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  3824. #endif
  3825.  
  3826. // Is x an array?
  3827.  
  3828. #ifndef ISARY
  3829. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  3830. #endif
  3831.  
  3832. // Is x a structure, union, or enumeration TAG?
  3833. #ifndef ISTAG
  3834. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  3835. #endif
  3836.  
  3837. #ifndef INCREF
  3838. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  3839. #endif
  3840. #ifndef DECREF
  3841. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  3842. #endif
  3843.  
  3844. //
  3845. // Auxiliary entry format.
  3846. //
  3847.  
  3848. typedef union _IMAGE_AUX_SYMBOL {
  3849.     struct {
  3850.         DWORD    TagIndex;                      // struct, union, or enum tag index
  3851.         union {
  3852.             struct {
  3853.                 WORD    Linenumber;             // declaration line number
  3854.                 WORD    Size;                   // size of struct, union, or enum
  3855.             } LnSz;
  3856.            DWORD    TotalSize;
  3857.         } Misc;
  3858.         union {
  3859.             struct {                            // if ISFCN, tag, or .bb
  3860.                 DWORD    PointerToLinenumber;
  3861.                 DWORD    PointerToNextFunction;
  3862.             } Function;
  3863.             struct {                            // if ISARY, up to 4 dimen.
  3864.                 WORD     Dimension[4];
  3865.             } Array;
  3866.         } FcnAry;
  3867.         WORD    TvIndex;                        // tv index
  3868.     } Sym;
  3869.     struct {
  3870.         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
  3871.     } File;
  3872.     struct {
  3873.         DWORD   Length;                         // section length
  3874.         WORD    NumberOfRelocations;            // number of relocation entries
  3875.         WORD    NumberOfLinenumbers;            // number of line numbers
  3876.         DWORD   CheckSum;                       // checksum for communal
  3877.         SHORT   Number;                         // section number to associate with
  3878.         BYTE    Selection;                      // communal selection type
  3879.     } Section;
  3880. } IMAGE_AUX_SYMBOL;
  3881. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  3882.  
  3883. #define IMAGE_SIZEOF_AUX_SYMBOL             18
  3884.  
  3885. //
  3886. // Communal selection types.
  3887. //
  3888.  
  3889. #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
  3890. #define IMAGE_COMDAT_SELECT_ANY             2
  3891. #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
  3892. #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
  3893. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
  3894. #define IMAGE_COMDAT_SELECT_LARGEST         6
  3895. #define IMAGE_COMDAT_SELECT_NEWEST          7
  3896.  
  3897. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
  3898. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
  3899. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
  3900.  
  3901. //
  3902. // Relocation format.
  3903. //
  3904.  
  3905. typedef struct _IMAGE_RELOCATION {
  3906.     union {
  3907.         DWORD   VirtualAddress;
  3908.         DWORD   RelocCount;             // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
  3909.     };
  3910.     DWORD   SymbolTableIndex;
  3911.     WORD    Type;
  3912. } IMAGE_RELOCATION;
  3913. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  3914.  
  3915. #define IMAGE_SIZEOF_RELOCATION         10
  3916.  
  3917. //
  3918. // I386 relocation types.
  3919. //
  3920.  
  3921. #define IMAGE_REL_I386_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  3922. #define IMAGE_REL_I386_DIR16            0x0001  // Direct 16-bit reference to the symbols virtual address
  3923. #define IMAGE_REL_I386_REL16            0x0002  // PC-relative 16-bit reference to the symbols virtual address
  3924. #define IMAGE_REL_I386_DIR32            0x0006  // Direct 32-bit reference to the symbols virtual address
  3925. #define IMAGE_REL_I386_DIR32NB          0x0007  // Direct 32-bit reference to the symbols virtual address, base not included
  3926. #define IMAGE_REL_I386_SEG12            0x0009  // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  3927. #define IMAGE_REL_I386_SECTION          0x000A
  3928. #define IMAGE_REL_I386_SECREL           0x000B
  3929. #define IMAGE_REL_I386_REL32            0x0014  // PC-relative 32-bit reference to the symbols virtual address
  3930.  
  3931. //
  3932. // MIPS relocation types.
  3933. //
  3934.  
  3935. #define IMAGE_REL_MIPS_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  3936. #define IMAGE_REL_MIPS_REFHALF          0x0001
  3937. #define IMAGE_REL_MIPS_REFWORD          0x0002
  3938. #define IMAGE_REL_MIPS_JMPADDR          0x0003
  3939. #define IMAGE_REL_MIPS_REFHI            0x0004
  3940. #define IMAGE_REL_MIPS_REFLO            0x0005
  3941. #define IMAGE_REL_MIPS_GPREL            0x0006
  3942. #define IMAGE_REL_MIPS_LITERAL          0x0007
  3943. #define IMAGE_REL_MIPS_SECTION          0x000A
  3944. #define IMAGE_REL_MIPS_SECREL           0x000B
  3945. #define IMAGE_REL_MIPS_SECRELLO         0x000C  // Low 16-bit section relative referemce (used for >32k TLS)
  3946. #define IMAGE_REL_MIPS_SECRELHI         0x000D  // High 16-bit section relative reference (used for >32k TLS)
  3947. #define IMAGE_REL_MIPS_REFWORDNB        0x0022
  3948. #define IMAGE_REL_MIPS_PAIR             0x0025
  3949.  
  3950. //
  3951. // Alpha Relocation types.
  3952. //
  3953.  
  3954. #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
  3955. #define IMAGE_REL_ALPHA_REFLONG         0x0001
  3956. #define IMAGE_REL_ALPHA_REFQUAD         0x0002
  3957. #define IMAGE_REL_ALPHA_GPREL32         0x0003
  3958. #define IMAGE_REL_ALPHA_LITERAL         0x0004
  3959. #define IMAGE_REL_ALPHA_LITUSE          0x0005
  3960. #define IMAGE_REL_ALPHA_GPDISP          0x0006
  3961. #define IMAGE_REL_ALPHA_BRADDR          0x0007
  3962. #define IMAGE_REL_ALPHA_HINT            0x0008
  3963. #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
  3964. #define IMAGE_REL_ALPHA_REFHI           0x000A
  3965. #define IMAGE_REL_ALPHA_REFLO           0x000B
  3966. #define IMAGE_REL_ALPHA_PAIR            0x000C
  3967. #define IMAGE_REL_ALPHA_MATCH           0x000D
  3968. #define IMAGE_REL_ALPHA_SECTION         0x000E
  3969. #define IMAGE_REL_ALPHA_SECREL          0x000F
  3970. #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
  3971. #define IMAGE_REL_ALPHA_SECRELLO        0x0011  // Low 16-bit section relative reference
  3972. #define IMAGE_REL_ALPHA_SECRELHI        0x0012  // High 16-bit section relative reference
  3973.  
  3974. //
  3975. // IBM PowerPC relocation types.
  3976. //
  3977.  
  3978. #define IMAGE_REL_PPC_ABSOLUTE          0x0000  // NOP
  3979. #define IMAGE_REL_PPC_ADDR64            0x0001  // 64-bit address
  3980. #define IMAGE_REL_PPC_ADDR32            0x0002  // 32-bit address
  3981. #define IMAGE_REL_PPC_ADDR24            0x0003  // 26-bit address, shifted left 2 (branch absolute)
  3982. #define IMAGE_REL_PPC_ADDR16            0x0004  // 16-bit address
  3983. #define IMAGE_REL_PPC_ADDR14            0x0005  // 16-bit address, shifted left 2 (load doubleword)
  3984. #define IMAGE_REL_PPC_REL24             0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
  3985. #define IMAGE_REL_PPC_REL14             0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  3986. #define IMAGE_REL_PPC_TOCREL16          0x0008  // 16-bit offset from TOC base
  3987. #define IMAGE_REL_PPC_TOCREL14          0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  3988.  
  3989. #define IMAGE_REL_PPC_ADDR32NB          0x000A  // 32-bit addr w/o image base
  3990. #define IMAGE_REL_PPC_SECREL            0x000B  // va of containing section (as in an image sectionhdr)
  3991. #define IMAGE_REL_PPC_SECTION           0x000C  // sectionheader number
  3992. #define IMAGE_REL_PPC_IFGLUE            0x000D  // substitute TOC restore instruction iff symbol is glue code
  3993. #define IMAGE_REL_PPC_IMGLUE            0x000E  // symbol is glue code; virtual address is TOC restore instruction
  3994. #define IMAGE_REL_PPC_SECREL16          0x000F  // va of containing section (limited to 16 bits)
  3995. #define IMAGE_REL_PPC_REFHI             0x0010
  3996. #define IMAGE_REL_PPC_REFLO             0x0011
  3997. #define IMAGE_REL_PPC_PAIR              0x0012
  3998. #define IMAGE_REL_PPC_SECRELLO          0x0013  // Low 16-bit section relative reference (used for >32k TLS)
  3999. #define IMAGE_REL_PPC_SECRELHI          0x0014  // High 16-bit section relative reference (used for >32k TLS)
  4000.  
  4001. #define IMAGE_REL_PPC_TYPEMASK          0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
  4002.  
  4003. // Flag bits in IMAGE_RELOCATION.TYPE
  4004.  
  4005. #define IMAGE_REL_PPC_NEG               0x0100  // subtract reloc value rather than adding it
  4006. #define IMAGE_REL_PPC_BRTAKEN           0x0200  // fix branch prediction bit to predict branch taken
  4007. #define IMAGE_REL_PPC_BRNTAKEN          0x0400  // fix branch prediction bit to predict branch not taken
  4008. #define IMAGE_REL_PPC_TOCDEFN           0x0800  // toc slot defined in file (or, data in toc)
  4009.  
  4010. //
  4011. // Line number format.
  4012. //
  4013.  
  4014. typedef struct _IMAGE_LINENUMBER {
  4015.     union {
  4016.         DWORD   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
  4017.         DWORD   VirtualAddress;                 // Virtual address of line number.
  4018.     } Type;
  4019.     WORD    Linenumber;                         // Line number.
  4020. } IMAGE_LINENUMBER;
  4021. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  4022.  
  4023. #define IMAGE_SIZEOF_LINENUMBER              6
  4024.  
  4025. #include "poppack.h"                        // Back to 4 byte packing
  4026.  
  4027. //
  4028. // Based relocation format.
  4029. //
  4030.  
  4031. typedef struct _IMAGE_BASE_RELOCATION {
  4032.     DWORD   VirtualAddress;
  4033.     DWORD   SizeOfBlock;
  4034. //  WORD    TypeOffset[1];
  4035. } IMAGE_BASE_RELOCATION;
  4036. typedef IMAGE_BASE_RELOCATION UNALIGNED * PIMAGE_BASE_RELOCATION;
  4037.  
  4038. #define IMAGE_SIZEOF_BASE_RELOCATION         8
  4039.  
  4040. //
  4041. // Based relocation types.
  4042. //
  4043.  
  4044. #define IMAGE_REL_BASED_ABSOLUTE              0
  4045. #define IMAGE_REL_BASED_HIGH                  1
  4046. #define IMAGE_REL_BASED_LOW                   2
  4047. #define IMAGE_REL_BASED_HIGHLOW               3
  4048. #define IMAGE_REL_BASED_HIGHADJ               4
  4049. #define IMAGE_REL_BASED_MIPS_JMPADDR          5
  4050. #define IMAGE_REL_BASED_SECTION               6
  4051. #define IMAGE_REL_BASED_REL32                 7
  4052.  
  4053. //
  4054. // Archive format.
  4055. //
  4056.  
  4057. #define IMAGE_ARCHIVE_START_SIZE             8
  4058. #define IMAGE_ARCHIVE_START                  "!<arch>\n"
  4059. #define IMAGE_ARCHIVE_END                    "`\n"
  4060. #define IMAGE_ARCHIVE_PAD                    "\n"
  4061. #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
  4062. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
  4063.  
  4064. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  4065.     BYTE     Name[16];                          // File member name - `/' terminated.
  4066.     BYTE     Date[12];                          // File member date - decimal.
  4067.     BYTE     UserID[6];                         // File member user id - decimal.
  4068.     BYTE     GroupID[6];                        // File member group id - decimal.
  4069.     BYTE     Mode[8];                           // File member mode - octal.
  4070.     BYTE     Size[10];                          // File member size - decimal.
  4071.     BYTE     EndHeader[2];                      // String to end header.
  4072. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  4073.  
  4074. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
  4075.  
  4076. //
  4077. // DLL support.
  4078. //
  4079.  
  4080. //
  4081. // Export Format
  4082. //
  4083.  
  4084. typedef struct _IMAGE_EXPORT_DIRECTORY {
  4085.     DWORD   Characteristics;
  4086.     DWORD   TimeDateStamp;
  4087.     WORD    MajorVersion;
  4088.     WORD    MinorVersion;
  4089.     DWORD   Name;
  4090.     DWORD   Base;
  4091.     DWORD   NumberOfFunctions;
  4092.     DWORD   NumberOfNames;
  4093.     PDWORD  *AddressOfFunctions;
  4094.     PDWORD  *AddressOfNames;
  4095.     PWORD   *AddressOfNameOrdinals;
  4096. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  4097.  
  4098. //
  4099. // Import Format
  4100. //
  4101.  
  4102. typedef struct _IMAGE_IMPORT_BY_NAME {
  4103.     WORD    Hint;
  4104.     BYTE    Name[1];
  4105. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  4106.  
  4107. typedef struct _IMAGE_THUNK_DATA {
  4108.     union {
  4109.         PBYTE  ForwarderString;
  4110.         PDWORD Function;
  4111.         DWORD Ordinal;
  4112.         PIMAGE_IMPORT_BY_NAME AddressOfData;
  4113.     } u1;
  4114. } IMAGE_THUNK_DATA;
  4115. typedef IMAGE_THUNK_DATA * PIMAGE_THUNK_DATA;
  4116.  
  4117. #define IMAGE_ORDINAL_FLAG 0x80000000
  4118. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
  4119. #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
  4120.  
  4121. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  4122.     union {
  4123.         DWORD   Characteristics;                // 0 for terminating null import descriptor
  4124.         PIMAGE_THUNK_DATA OriginalFirstThunk;   // RVA to original unbound IAT
  4125.     };
  4126.     DWORD   TimeDateStamp;                  // 0 if not bound,
  4127.                                             // -1 if bound, and real date\time stamp
  4128.                                             //     in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
  4129.                                             // O.W. date/time stamp of DLL bound to (Old BIND)
  4130.  
  4131.     DWORD   ForwarderChain;                 // -1 if no forwarders
  4132.     DWORD   Name;
  4133.     PIMAGE_THUNK_DATA FirstThunk;           // RVA to IAT (if bound this IAT has actual addresses)
  4134. } IMAGE_IMPORT_DESCRIPTOR;
  4135. typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
  4136.  
  4137. //
  4138. // New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  4139. //
  4140.  
  4141. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  4142.     DWORD   TimeDateStamp;
  4143.     WORD    OffsetModuleName;
  4144.     WORD    NumberOfModuleForwarderRefs;
  4145. // Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
  4146. } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  4147.  
  4148. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  4149.     DWORD   TimeDateStamp;
  4150.     WORD    OffsetModuleName;
  4151.     WORD    Reserved;
  4152. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  4153.  
  4154.  
  4155. //
  4156. // Thread Local Storage
  4157. //
  4158.  
  4159. typedef VOID
  4160. (NTAPI *PIMAGE_TLS_CALLBACK) (
  4161.     PVOID DllHandle,
  4162.     DWORD Reason,
  4163.     PVOID Reserved
  4164.     );
  4165.  
  4166. typedef struct _IMAGE_TLS_DIRECTORY {
  4167.     DWORD   StartAddressOfRawData;
  4168.     DWORD   EndAddressOfRawData;
  4169.     PDWORD  AddressOfIndex;
  4170.     PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
  4171.     DWORD   SizeOfZeroFill;
  4172.     DWORD   Characteristics;
  4173. } IMAGE_TLS_DIRECTORY, *PIMAGE_TLS_DIRECTORY;
  4174.  
  4175.  
  4176. //
  4177. // Resource Format.
  4178. //
  4179.  
  4180. //
  4181. // Resource directory consists of two counts, following by a variable length
  4182. // array of directory entries.  The first count is the number of entries at
  4183. // beginning of the array that have actual names associated with each entry.
  4184. // The entries are in ascending order, case insensitive strings.  The second
  4185. // count is the number of entries that immediately follow the named entries.
  4186. // This second count identifies the number of entries that have 16-bit integer
  4187. // Ids as their name.  These entries are also sorted in ascending order.
  4188. //
  4189. // This structure allows fast lookup by either name or number, but for any
  4190. // given resource entry only one form of lookup is supported, not both.
  4191. // This is consistant with the syntax of the .RC file and the .RES file.
  4192. //
  4193.  
  4194. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  4195.     DWORD   Characteristics;
  4196.     DWORD   TimeDateStamp;
  4197.     WORD    MajorVersion;
  4198.     WORD    MinorVersion;
  4199.     WORD    NumberOfNamedEntries;
  4200.     WORD    NumberOfIdEntries;
  4201. //  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  4202. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  4203.  
  4204. #define IMAGE_RESOURCE_NAME_IS_STRING        0x80000000
  4205. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY     0x80000000
  4206.  
  4207. //
  4208. // Each directory contains the 32-bit Name of the entry and an offset,
  4209. // relative to the beginning of the resource directory of the data associated
  4210. // with this directory entry.  If the name of the entry is an actual text
  4211. // string instead of an integer Id, then the high order bit of the name field
  4212. // is set to one and the low order 31-bits are an offset, relative to the
  4213. // beginning of the resource directory of the string, which is of type
  4214. // IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
  4215. // low-order 16-bits are the integer Id that identify this resource directory
  4216. // entry. If the directory entry is yet another resource directory (i.e. a
  4217. // subdirectory), then the high order bit of the offset field will be
  4218. // set to indicate this.  Otherwise the high bit is clear and the offset
  4219. // field points to a resource data entry.
  4220. //
  4221.  
  4222. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  4223.     union {
  4224.         struct {
  4225.             DWORD NameOffset:31;
  4226.             DWORD NameIsString:1;
  4227.         };
  4228.         DWORD   Name;
  4229.         WORD    Id;
  4230.     };
  4231.     union {
  4232.         DWORD   OffsetToData;
  4233.         struct {
  4234.             DWORD   OffsetToDirectory:31;
  4235.             DWORD   DataIsDirectory:1;
  4236.         };
  4237.     };
  4238. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  4239.  
  4240. //
  4241. // For resource directory entries that have actual string names, the Name
  4242. // field of the directory entry points to an object of the following type.
  4243. // All of these string objects are stored together after the last resource
  4244. // directory entry and before the first resource data object.  This minimizes
  4245. // the impact of these variable length objects on the alignment of the fixed
  4246. // size directory entry objects.
  4247. //
  4248.  
  4249. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  4250.     WORD    Length;
  4251.     CHAR    NameString[ 1 ];
  4252. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  4253.  
  4254.  
  4255. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  4256.     WORD    Length;
  4257.     WCHAR   NameString[ 1 ];
  4258. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  4259.  
  4260.  
  4261. //
  4262. // Each resource data entry describes a leaf node in the resource directory
  4263. // tree.  It contains an offset, relative to the beginning of the resource
  4264. // directory of the data for the resource, a size field that gives the number
  4265. // of bytes of data at that offset, a CodePage that should be used when
  4266. // decoding code point values within the resource data.  Typically for new
  4267. // applications the code page would be the unicode code page.
  4268. //
  4269.  
  4270. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  4271.     DWORD   OffsetToData;
  4272.     DWORD   Size;
  4273.     DWORD   CodePage;
  4274.     DWORD   Reserved;
  4275. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  4276.  
  4277. //
  4278. // Load Configuration Directory Entry
  4279. //
  4280.  
  4281. typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
  4282.     DWORD   Characteristics;
  4283.     DWORD   TimeDateStamp;
  4284.     WORD    MajorVersion;
  4285.     WORD    MinorVersion;
  4286.     DWORD   GlobalFlagsClear;
  4287.     DWORD   GlobalFlagsSet;
  4288.     DWORD   CriticalSectionDefaultTimeout;
  4289.     DWORD   DeCommitFreeBlockThreshold;
  4290.     DWORD   DeCommitTotalFreeThreshold;
  4291.     PVOID   LockPrefixTable;
  4292.     DWORD   MaximumAllocationSize;
  4293.     DWORD   VirtualMemoryThreshold;
  4294.     DWORD   ProcessHeapFlags;
  4295.     DWORD   ProcessAffinityMask;
  4296.     DWORD   Reserved[ 3 ];
  4297. } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
  4298.  
  4299.  
  4300. //
  4301. // Function table entry format for MIPS/ALPHA images.  Function table is
  4302. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  4303. // This definition duplicates ones in ntmips.h and ntalpha.h for use
  4304. // by portable image file mungers.
  4305. //
  4306.  
  4307. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  4308.     DWORD BeginAddress;
  4309.     DWORD EndAddress;
  4310.     PVOID ExceptionHandler;
  4311.     PVOID HandlerData;
  4312.     DWORD PrologEndAddress;
  4313. } IMAGE_RUNTIME_FUNCTION_ENTRY, *PIMAGE_RUNTIME_FUNCTION_ENTRY;
  4314.  
  4315. //
  4316. // Debug Format
  4317. //
  4318.  
  4319. typedef struct _IMAGE_DEBUG_DIRECTORY {
  4320.     DWORD   Characteristics;
  4321.     DWORD   TimeDateStamp;
  4322.     WORD    MajorVersion;
  4323.     WORD    MinorVersion;
  4324.     DWORD   Type;
  4325.     DWORD   SizeOfData;
  4326.     DWORD   AddressOfRawData;
  4327.     DWORD   PointerToRawData;
  4328. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  4329.  
  4330. #define IMAGE_DEBUG_TYPE_UNKNOWN          0
  4331. #define IMAGE_DEBUG_TYPE_COFF             1
  4332. #define IMAGE_DEBUG_TYPE_CODEVIEW         2
  4333. #define IMAGE_DEBUG_TYPE_FPO              3
  4334. #define IMAGE_DEBUG_TYPE_MISC             4
  4335. #define IMAGE_DEBUG_TYPE_EXCEPTION        5
  4336. #define IMAGE_DEBUG_TYPE_FIXUP            6
  4337. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC      7
  4338. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC    8
  4339.  
  4340.  
  4341. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  4342.     DWORD   NumberOfSymbols;
  4343.     DWORD   LvaToFirstSymbol;
  4344.     DWORD   NumberOfLinenumbers;
  4345.     DWORD   LvaToFirstLinenumber;
  4346.     DWORD   RvaToFirstByteOfCode;
  4347.     DWORD   RvaToLastByteOfCode;
  4348.     DWORD   RvaToFirstByteOfData;
  4349.     DWORD   RvaToLastByteOfData;
  4350. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  4351.  
  4352. #define FRAME_FPO       0
  4353. #define FRAME_TRAP      1
  4354. #define FRAME_TSS       2
  4355. #define FRAME_NONFPO    3
  4356.  
  4357. typedef struct _FPO_DATA {
  4358.     DWORD       ulOffStart;             // offset 1st byte of function code
  4359.     DWORD       cbProcSize;             // # bytes in function
  4360.     DWORD       cdwLocals;              // # bytes in locals/4
  4361.     WORD        cdwParams;              // # bytes in params/4
  4362.     WORD        cbProlog : 8;           // # bytes in prolog
  4363.     WORD        cbRegs   : 3;           // # regs saved
  4364.     WORD        fHasSEH  : 1;           // TRUE if SEH in func
  4365.     WORD        fUseBP   : 1;           // TRUE if EBP has been allocated
  4366.     WORD        reserved : 1;           // reserved for future use
  4367.     WORD        cbFrame  : 2;           // frame type
  4368. } FPO_DATA, *PFPO_DATA;
  4369. #define SIZEOF_RFPO_DATA 16
  4370.  
  4371.  
  4372. #define IMAGE_DEBUG_MISC_EXENAME    1
  4373.  
  4374. typedef struct _IMAGE_DEBUG_MISC {
  4375.     DWORD       DataType;               // type of misc data, see defines
  4376.     DWORD       Length;                 // total length of record, rounded to four
  4377.                                         // byte multiple.
  4378.     BOOLEAN     Unicode;                // TRUE if data is unicode string
  4379.     BYTE        Reserved[ 3 ];
  4380.     BYTE        Data[ 1 ];              // Actual data
  4381. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  4382.  
  4383.  
  4384. //
  4385. // Function table extracted from MIPS/ALPHA images.  Does not contain
  4386. // information needed only for runtime support.  Just those fields for
  4387. // each entry needed by a debugger.
  4388. //
  4389.  
  4390. typedef struct _IMAGE_FUNCTION_ENTRY {
  4391.     DWORD   StartingAddress;
  4392.     DWORD   EndingAddress;
  4393.     DWORD   EndOfPrologue;
  4394. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  4395.  
  4396. //
  4397. // Debugging information can be stripped from an image file and placed
  4398. // in a separate .DBG file, whose file name part is the same as the
  4399. // image file name part (e.g. symbols for CMD.EXE could be stripped
  4400. // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  4401. // flag in the Characteristics field of the file header.  The beginning of
  4402. // the .DBG file contains the following structure which captures certain
  4403. // information from the image file.  This allows a debug to proceed even if
  4404. // the original image file is not accessable.  This header is followed by
  4405. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  4406. // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
  4407. // the image file contain file offsets relative to the beginning of the
  4408. // .DBG file.
  4409. //
  4410. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  4411. // is left in the image file, but not mapped.  This allows a debugger to
  4412. // compute the name of the .DBG file, from the name of the image in the
  4413. // IMAGE_DEBUG_MISC structure.
  4414. //
  4415.  
  4416. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  4417.     WORD        Signature;
  4418.     WORD        Flags;
  4419.     WORD        Machine;
  4420.     WORD        Characteristics;
  4421.     DWORD       TimeDateStamp;
  4422.     DWORD       CheckSum;
  4423.     DWORD       ImageBase;
  4424.     DWORD       SizeOfImage;
  4425.     DWORD       NumberOfSections;
  4426.     DWORD       ExportedNamesSize;
  4427.     DWORD       DebugDirectorySize;
  4428.     DWORD       SectionAlignment;
  4429.     DWORD       Reserved[2];
  4430. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  4431.  
  4432. #define IMAGE_SEPARATE_DEBUG_SIGNATURE  0x4944
  4433.  
  4434. #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
  4435. #define IMAGE_SEPARATE_DEBUG_MISMATCH   0x8000  // when DBG was updated, the
  4436.                                                 // old checksum didn't match.
  4437.  
  4438. #include "poppack.h"                        // Return to the default
  4439.  
  4440. //
  4441. // End Image Format
  4442. //
  4443.  
  4444. //
  4445. // for move macros
  4446. //
  4447. #include <string.h>
  4448. #define HEAP_NO_SERIALIZE               0x00000001      
  4449. #define HEAP_GROWABLE                   0x00000002      
  4450. #define HEAP_GENERATE_EXCEPTIONS        0x00000004      
  4451. #define HEAP_ZERO_MEMORY                0x00000008      
  4452. #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010      
  4453. #define HEAP_TAIL_CHECKING_ENABLED      0x00000020      
  4454. #define HEAP_FREE_CHECKING_ENABLED      0x00000040      
  4455. #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080      
  4456. #define HEAP_CREATE_ALIGN_16            0x00010000      
  4457. #define HEAP_CREATE_ENABLE_TRACING      0x00020000      
  4458. #define HEAP_MAXIMUM_TAG                0x0FFF              
  4459. #define HEAP_PSEUDO_TAG_FLAG            0x8000              
  4460. #define HEAP_TAG_SHIFT                  16                  
  4461. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((DWORD)((b) + ((o) << 16)))  
  4462.  
  4463. #define IS_TEXT_UNICODE_ASCII16               0x0001
  4464. #define IS_TEXT_UNICODE_REVERSE_ASCII16       0x0010
  4465.  
  4466. #define IS_TEXT_UNICODE_STATISTICS            0x0002
  4467. #define IS_TEXT_UNICODE_REVERSE_STATISTICS    0x0020
  4468.  
  4469. #define IS_TEXT_UNICODE_CONTROLS              0x0004
  4470. #define IS_TEXT_UNICODE_REVERSE_CONTROLS      0x0040
  4471.  
  4472. #define IS_TEXT_UNICODE_SIGNATURE             0x0008
  4473. #define IS_TEXT_UNICODE_REVERSE_SIGNATURE     0x0080
  4474.  
  4475. #define IS_TEXT_UNICODE_ILLEGAL_CHARS         0x0100
  4476. #define IS_TEXT_UNICODE_ODD_LENGTH            0x0200
  4477. #define IS_TEXT_UNICODE_DBCS_LEADBYTE         0x0400
  4478. #define IS_TEXT_UNICODE_NULL_BYTES            0x1000
  4479.  
  4480. #define IS_TEXT_UNICODE_UNICODE_MASK          0x000F
  4481. #define IS_TEXT_UNICODE_REVERSE_MASK          0x00F0
  4482. #define IS_TEXT_UNICODE_NOT_UNICODE_MASK      0x0F00
  4483. #define IS_TEXT_UNICODE_NOT_ASCII_MASK        0xF000
  4484.  
  4485. #define COMPRESSION_FORMAT_NONE          (0x0000)   
  4486. #define COMPRESSION_FORMAT_DEFAULT       (0x0001)   
  4487. #define COMPRESSION_FORMAT_LZNT1         (0x0002)   
  4488. #define COMPRESSION_ENGINE_STANDARD      (0x0000)   
  4489. #define COMPRESSION_ENGINE_MAXIMUM       (0x0100)   
  4490. #if defined(_M_IX86) || defined(_M_MRX000) || defined(_M_ALPHA)
  4491.  
  4492. #if defined(_M_MRX000)
  4493. NTSYSAPI
  4494. DWORD
  4495. NTAPI
  4496. RtlEqualMemory (
  4497.     CONST VOID *Source1,
  4498.     CONST VOID *Source2,
  4499.     DWORD Length
  4500.     );
  4501.  
  4502. #else
  4503. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  4504. #endif
  4505.  
  4506. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  4507. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  4508. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  4509. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  4510.  
  4511. #else // _M_PPC
  4512.  
  4513. NTSYSAPI
  4514. DWORD
  4515. NTAPI
  4516. RtlEqualMemory (
  4517.     CONST VOID *Source1,
  4518.     CONST VOID *Source2,
  4519.     DWORD Length
  4520.     );
  4521.  
  4522. NTSYSAPI
  4523. VOID
  4524. NTAPI
  4525. RtlCopyMemory (
  4526.    VOID UNALIGNED *Destination,
  4527.    CONST VOID UNALIGNED *Source,
  4528.    DWORD Length
  4529.    );
  4530.  
  4531. NTSYSAPI
  4532. VOID
  4533. NTAPI
  4534. RtlCopyMemory32 (
  4535.    VOID UNALIGNED *Destination,
  4536.    CONST VOID UNALIGNED *Source,
  4537.    DWORD Length
  4538.    );
  4539.  
  4540. NTSYSAPI
  4541. VOID
  4542. NTAPI
  4543. RtlMoveMemory (
  4544.    VOID UNALIGNED *Destination,
  4545.    CONST VOID UNALIGNED *Source,
  4546.    DWORD Length
  4547.    );
  4548.  
  4549. NTSYSAPI
  4550. VOID
  4551. NTAPI
  4552. RtlFillMemory (
  4553.    VOID UNALIGNED *Destination,
  4554.    DWORD Length,
  4555.    BYTE  Fill
  4556.    );
  4557.  
  4558. NTSYSAPI
  4559. VOID
  4560. NTAPI
  4561. RtlZeroMemory (
  4562.    VOID UNALIGNED *Destination,
  4563.    DWORD Length
  4564.    );
  4565. #endif
  4566.  
  4567. typedef struct _MESSAGE_RESOURCE_ENTRY {
  4568.     WORD   Length;
  4569.     WORD   Flags;
  4570.     BYTE  Text[ 1 ];
  4571. } MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;
  4572.  
  4573. #define MESSAGE_RESOURCE_UNICODE 0x0001
  4574.  
  4575. typedef struct _MESSAGE_RESOURCE_BLOCK {
  4576.     DWORD LowId;
  4577.     DWORD HighId;
  4578.     DWORD OffsetToEntries;
  4579. } MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;
  4580.  
  4581. typedef struct _MESSAGE_RESOURCE_DATA {
  4582.     DWORD NumberOfBlocks;
  4583.     MESSAGE_RESOURCE_BLOCK Blocks[ 1 ];
  4584. } MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;
  4585.  
  4586.  
  4587. typedef struct _RTL_CRITICAL_SECTION_DEBUG {
  4588.     WORD   Type;
  4589.     WORD   CreatorBackTraceIndex;
  4590.     struct _RTL_CRITICAL_SECTION *CriticalSection;
  4591.     LIST_ENTRY ProcessLocksList;
  4592.     DWORD EntryCount;
  4593.     DWORD ContentionCount;
  4594.     DWORD Spare[ 2 ];
  4595. } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG;
  4596.  
  4597. #define RTL_CRITSECT_TYPE 0
  4598. #define RTL_RESOURCE_TYPE 1
  4599.  
  4600. typedef struct _RTL_CRITICAL_SECTION {
  4601.     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
  4602.  
  4603.     //
  4604.     //  The following three fields control entering and exiting the critical
  4605.     //  section for the resource
  4606.     //
  4607.  
  4608.     LONG LockCount;
  4609.     LONG RecursionCount;
  4610.     HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
  4611.     HANDLE LockSemaphore;
  4612.     DWORD Reserved;
  4613. } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
  4614. #define DLL_PROCESS_ATTACH 1    
  4615. #define DLL_THREAD_ATTACH  2    
  4616. #define DLL_THREAD_DETACH  3    
  4617. #define DLL_PROCESS_DETACH 0    
  4618.  
  4619. //
  4620. // Defines for the READ flags for Eventlogging
  4621. //
  4622. #define EVENTLOG_SEQUENTIAL_READ        0X0001
  4623. #define EVENTLOG_SEEK_READ              0X0002
  4624. #define EVENTLOG_FORWARDS_READ          0X0004
  4625. #define EVENTLOG_BACKWARDS_READ         0X0008
  4626.  
  4627. //
  4628. // The types of events that can be logged.
  4629. //
  4630. #define EVENTLOG_SUCCESS                0X0000
  4631. #define EVENTLOG_ERROR_TYPE             0x0001
  4632. #define EVENTLOG_WARNING_TYPE           0x0002
  4633. #define EVENTLOG_INFORMATION_TYPE       0x0004
  4634. #define EVENTLOG_AUDIT_SUCCESS          0x0008
  4635. #define EVENTLOG_AUDIT_FAILURE          0x0010
  4636.  
  4637. //
  4638. // Defines for the WRITE flags used by Auditing for paired events
  4639. // These are not implemented in Product 1
  4640. //
  4641.  
  4642. #define EVENTLOG_START_PAIRED_EVENT    0x0001
  4643. #define EVENTLOG_END_PAIRED_EVENT      0x0002
  4644. #define EVENTLOG_END_ALL_PAIRED_EVENTS 0x0004
  4645. #define EVENTLOG_PAIRED_EVENT_ACTIVE   0x0008
  4646. #define EVENTLOG_PAIRED_EVENT_INACTIVE 0x0010
  4647.  
  4648. //
  4649. // Structure that defines the header of the Eventlog record. This is the
  4650. // fixed-sized portion before all the variable-length strings, binary
  4651. // data and pad bytes.
  4652. //
  4653. // TimeGenerated is the time it was generated at the client.
  4654. // TimeWritten is the time it was put into the log at the server end.
  4655. //
  4656.  
  4657. typedef struct _EVENTLOGRECORD {
  4658.     DWORD  Length;        // Length of full record
  4659.     DWORD  Reserved;      // Used by the service
  4660.     DWORD  RecordNumber;  // Absolute record number
  4661.     DWORD  TimeGenerated; // Seconds since 1-1-1970
  4662.     DWORD  TimeWritten;   // Seconds since 1-1-1970
  4663.     DWORD  EventID;
  4664.     WORD   EventType;
  4665.     WORD   NumStrings;
  4666.     WORD   EventCategory;
  4667.     WORD   ReservedFlags; // For use with paired events (auditing)
  4668.     DWORD  ClosingRecordNumber; // For use with paired events (auditing)
  4669.     DWORD  StringOffset;  // Offset from beginning of record
  4670.     DWORD  UserSidLength;
  4671.     DWORD  UserSidOffset;
  4672.     DWORD  DataLength;
  4673.     DWORD  DataOffset;    // Offset from beginning of record
  4674.     //
  4675.     // Then follow:
  4676.     //
  4677.     // WCHAR SourceName[]
  4678.     // WCHAR Computername[]
  4679.     // SID   UserSid
  4680.     // WCHAR Strings[]
  4681.     // BYTE  Data[]
  4682.     // CHAR  Pad[]
  4683.     // DWORD Length;
  4684.     //
  4685. } EVENTLOGRECORD, *PEVENTLOGRECORD;
  4686.  
  4687. #define DBG_CONTINUE                    ((DWORD   )0x00010002L) 
  4688. #define DBG_TERMINATE_THREAD            ((DWORD   )0x40010003L) 
  4689. #define DBG_TERMINATE_PROCESS           ((DWORD   )0x40010004L) 
  4690. #define DBG_CONTROL_C                   ((DWORD   )0x40010005L) 
  4691. #define DBG_CONTROL_BREAK               ((DWORD   )0x40010008L) 
  4692. #define DBG_EXCEPTION_NOT_HANDLED       ((DWORD   )0x80010001L) 
  4693. //
  4694.  
  4695. // begin_ntddk begin_nthal
  4696. //
  4697. // Registry Specific Access Rights.
  4698. //
  4699.  
  4700. #define KEY_QUERY_VALUE         (0x0001)
  4701. #define KEY_SET_VALUE           (0x0002)
  4702. #define KEY_CREATE_SUB_KEY      (0x0004)
  4703. #define KEY_ENUMERATE_SUB_KEYS  (0x0008)
  4704. #define KEY_NOTIFY              (0x0010)
  4705. #define KEY_CREATE_LINK         (0x0020)
  4706.  
  4707. #define KEY_READ                ((STANDARD_RIGHTS_READ       |\
  4708.                                   KEY_QUERY_VALUE            |\
  4709.                                   KEY_ENUMERATE_SUB_KEYS     |\
  4710.                                   KEY_NOTIFY)                 \
  4711.                                   &                           \
  4712.                                  (~SYNCHRONIZE))
  4713.  
  4714.  
  4715. #define KEY_WRITE               ((STANDARD_RIGHTS_WRITE      |\
  4716.                                   KEY_SET_VALUE              |\
  4717.                                   KEY_CREATE_SUB_KEY)         \
  4718.                                   &                           \
  4719.                                  (~SYNCHRONIZE))
  4720.  
  4721. #define KEY_EXECUTE             ((KEY_READ)                   \
  4722.                                   &                           \
  4723.                                  (~SYNCHRONIZE))
  4724.  
  4725. #define KEY_ALL_ACCESS          ((STANDARD_RIGHTS_ALL        |\
  4726.                                   KEY_QUERY_VALUE            |\
  4727.                                   KEY_SET_VALUE              |\
  4728.                                   KEY_CREATE_SUB_KEY         |\
  4729.                                   KEY_ENUMERATE_SUB_KEYS     |\
  4730.                                   KEY_NOTIFY                 |\
  4731.                                   KEY_CREATE_LINK)            \
  4732.                                   &                           \
  4733.                                  (~SYNCHRONIZE))
  4734.  
  4735. //
  4736. // Open/Create Options
  4737. //
  4738.  
  4739. #define REG_OPTION_RESERVED         (0x00000000L)   // Parameter is reserved
  4740.  
  4741. #define REG_OPTION_NON_VOLATILE     (0x00000000L)   // Key is preserved
  4742.                                                     // when system is rebooted
  4743.  
  4744. #define REG_OPTION_VOLATILE         (0x00000001L)   // Key is not preserved
  4745.                                                     // when system is rebooted
  4746.  
  4747. #define REG_OPTION_CREATE_LINK      (0x00000002L)   // Created key is a
  4748.                                                     // symbolic link
  4749.  
  4750. #define REG_OPTION_BACKUP_RESTORE   (0x00000004L)   // open for backup or restore
  4751.                                                     // special access rules
  4752.                                                     // privilege required
  4753.  
  4754. #define REG_OPTION_OPEN_LINK        (0x00000008L)   // Open symbolic link
  4755.  
  4756. #define REG_LEGAL_OPTION            \
  4757.                 (REG_OPTION_RESERVED            |\
  4758.                  REG_OPTION_NON_VOLATILE        |\
  4759.                  REG_OPTION_VOLATILE            |\
  4760.                  REG_OPTION_CREATE_LINK         |\
  4761.                  REG_OPTION_BACKUP_RESTORE      |\
  4762.                  REG_OPTION_OPEN_LINK)
  4763.  
  4764. //
  4765. // Key creation/open disposition
  4766. //
  4767.  
  4768. #define REG_CREATED_NEW_KEY         (0x00000001L)   // New Registry Key created
  4769. #define REG_OPENED_EXISTING_KEY     (0x00000002L)   // Existing Key opened
  4770.  
  4771. //
  4772. // Key restore flags
  4773. //
  4774.  
  4775. #define REG_WHOLE_HIVE_VOLATILE     (0x00000001L)   // Restore whole hive volatile
  4776. #define REG_REFRESH_HIVE            (0x00000002L)   // Unwind changes to last flush
  4777. #define REG_NO_LAZY_FLUSH           (0x00000004L)   // Never lazy flush this hive
  4778.  
  4779. // end_ntddk end_nthal
  4780.  
  4781. //
  4782. // Notify filter values
  4783. //
  4784. #define REG_NOTIFY_CHANGE_NAME          (0x00000001L) // Create or delete (child)
  4785. #define REG_NOTIFY_CHANGE_ATTRIBUTES    (0x00000002L)
  4786. #define REG_NOTIFY_CHANGE_LAST_SET      (0x00000004L) // time stamp
  4787. #define REG_NOTIFY_CHANGE_SECURITY      (0x00000008L)
  4788.  
  4789. #define REG_LEGAL_CHANGE_FILTER                 \
  4790.                 (REG_NOTIFY_CHANGE_NAME          |\
  4791.                  REG_NOTIFY_CHANGE_ATTRIBUTES    |\
  4792.                  REG_NOTIFY_CHANGE_LAST_SET      |\
  4793.                  REG_NOTIFY_CHANGE_SECURITY)
  4794.  
  4795. //
  4796. //
  4797. // Predefined Value Types.
  4798. //
  4799.  
  4800. #define REG_NONE                    ( 0 )   // No value type
  4801. #define REG_SZ                      ( 1 )   // Unicode nul terminated string
  4802. #define REG_EXPAND_SZ               ( 2 )   // Unicode nul terminated string
  4803.                                             // (with environment variable references)
  4804. #define REG_BINARY                  ( 3 )   // Free form binary
  4805. #define REG_DWORD                   ( 4 )   // 32-bit number
  4806. #define REG_DWORD_LITTLE_ENDIAN     ( 4 )   // 32-bit number (same as REG_DWORD)
  4807. #define REG_DWORD_BIG_ENDIAN        ( 5 )   // 32-bit number
  4808. #define REG_LINK                    ( 6 )   // Symbolic Link (unicode)
  4809. #define REG_MULTI_SZ                ( 7 )   // Multiple Unicode strings
  4810. #define REG_RESOURCE_LIST           ( 8 )   // Resource list in the resource map
  4811. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 )  // Resource list in the hardware description
  4812. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  4813.  
  4814. // end_ntddk end_nthal
  4815.  
  4816. // begin_ntddk begin_nthal
  4817. //
  4818. // Service Types (Bit Mask)
  4819. //
  4820. #define SERVICE_KERNEL_DRIVER          0x00000001
  4821. #define SERVICE_FILE_SYSTEM_DRIVER     0x00000002
  4822. #define SERVICE_ADAPTER                0x00000004
  4823. #define SERVICE_RECOGNIZER_DRIVER      0x00000008
  4824.  
  4825. #define SERVICE_DRIVER                 (SERVICE_KERNEL_DRIVER | \
  4826.                                         SERVICE_FILE_SYSTEM_DRIVER | \
  4827.                                         SERVICE_RECOGNIZER_DRIVER)
  4828.  
  4829. #define SERVICE_WIN32_OWN_PROCESS      0x00000010
  4830. #define SERVICE_WIN32_SHARE_PROCESS    0x00000020
  4831. #define SERVICE_WIN32                  (SERVICE_WIN32_OWN_PROCESS | \
  4832.                                         SERVICE_WIN32_SHARE_PROCESS)
  4833.  
  4834. #define SERVICE_INTERACTIVE_PROCESS    0x00000100
  4835.  
  4836. #define SERVICE_TYPE_ALL               (SERVICE_WIN32  | \
  4837.                                         SERVICE_ADAPTER | \
  4838.                                         SERVICE_DRIVER  | \
  4839.                                         SERVICE_INTERACTIVE_PROCESS)
  4840.  
  4841. //
  4842. // Start Type
  4843. //
  4844.  
  4845. #define SERVICE_BOOT_START             0x00000000
  4846. #define SERVICE_SYSTEM_START           0x00000001
  4847. #define SERVICE_AUTO_START             0x00000002
  4848. #define SERVICE_DEMAND_START           0x00000003
  4849. #define SERVICE_DISABLED               0x00000004
  4850.  
  4851. //
  4852. // Error control type
  4853. //
  4854. #define SERVICE_ERROR_IGNORE           0x00000000
  4855. #define SERVICE_ERROR_NORMAL           0x00000001
  4856. #define SERVICE_ERROR_SEVERE           0x00000002
  4857. #define SERVICE_ERROR_CRITICAL         0x00000003
  4858.  
  4859. //
  4860. //
  4861. // Define the registry driver node enumerations
  4862. //
  4863.  
  4864. typedef enum _CM_SERVICE_NODE_TYPE {
  4865.     DriverType               = SERVICE_KERNEL_DRIVER,
  4866.     FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
  4867.     Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
  4868.     Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  4869.     AdapterType              = SERVICE_ADAPTER,
  4870.     RecognizerType           = SERVICE_RECOGNIZER_DRIVER
  4871. } SERVICE_NODE_TYPE;
  4872.  
  4873. typedef enum _CM_SERVICE_LOAD_TYPE {
  4874.     BootLoad    = SERVICE_BOOT_START,
  4875.     SystemLoad  = SERVICE_SYSTEM_START,
  4876.     AutoLoad    = SERVICE_AUTO_START,
  4877.     DemandLoad  = SERVICE_DEMAND_START,
  4878.     DisableLoad = SERVICE_DISABLED
  4879. } SERVICE_LOAD_TYPE;
  4880.  
  4881. typedef enum _CM_ERROR_CONTROL_TYPE {
  4882.     IgnoreError   = SERVICE_ERROR_IGNORE,
  4883.     NormalError   = SERVICE_ERROR_NORMAL,
  4884.     SevereError   = SERVICE_ERROR_SEVERE,
  4885.     CriticalError = SERVICE_ERROR_CRITICAL
  4886. } SERVICE_ERROR_TYPE;
  4887.  
  4888.  
  4889. //
  4890. // IOCTL_TAPE_ERASE definitions
  4891. //
  4892.  
  4893. #define TAPE_ERASE_SHORT            0L
  4894. #define TAPE_ERASE_LONG             1L
  4895.  
  4896. typedef struct _TAPE_ERASE {
  4897.     DWORD Type;
  4898.     BOOLEAN Immediate;
  4899. } TAPE_ERASE, *PTAPE_ERASE;
  4900.  
  4901. //
  4902. // IOCTL_TAPE_PREPARE definitions
  4903. //
  4904.  
  4905. #define TAPE_LOAD                   0L
  4906. #define TAPE_UNLOAD                 1L
  4907. #define TAPE_TENSION                2L
  4908. #define TAPE_LOCK                   3L
  4909. #define TAPE_UNLOCK                 4L
  4910. #define TAPE_FORMAT                 5L
  4911.  
  4912. typedef struct _TAPE_PREPARE {
  4913.     DWORD Operation;
  4914.     BOOLEAN Immediate;
  4915. } TAPE_PREPARE, *PTAPE_PREPARE;
  4916.  
  4917. //
  4918. // IOCTL_TAPE_WRITE_MARKS definitions
  4919. //
  4920.  
  4921. #define TAPE_SETMARKS               0L
  4922. #define TAPE_FILEMARKS              1L
  4923. #define TAPE_SHORT_FILEMARKS        2L
  4924. #define TAPE_LONG_FILEMARKS         3L
  4925.  
  4926. typedef struct _TAPE_WRITE_MARKS {
  4927.     DWORD Type;
  4928.     DWORD Count;
  4929.     BOOLEAN Immediate;
  4930. } TAPE_WRITE_MARKS, *PTAPE_WRITE_MARKS;
  4931.  
  4932. //
  4933. // IOCTL_TAPE_GET_POSITION definitions
  4934. //
  4935.  
  4936. #define TAPE_ABSOLUTE_POSITION       0L
  4937. #define TAPE_LOGICAL_POSITION        1L
  4938. #define TAPE_PSEUDO_LOGICAL_POSITION 2L
  4939.  
  4940. typedef struct _TAPE_GET_POSITION {
  4941.     DWORD Type;
  4942.     DWORD Partition;
  4943.     LARGE_INTEGER Offset;
  4944. } TAPE_GET_POSITION, *PTAPE_GET_POSITION;
  4945.  
  4946. //
  4947. // IOCTL_TAPE_SET_POSITION definitions
  4948. //
  4949.  
  4950. #define TAPE_REWIND                 0L
  4951. #define TAPE_ABSOLUTE_BLOCK         1L
  4952. #define TAPE_LOGICAL_BLOCK          2L
  4953. #define TAPE_PSEUDO_LOGICAL_BLOCK   3L
  4954. #define TAPE_SPACE_END_OF_DATA      4L
  4955. #define TAPE_SPACE_RELATIVE_BLOCKS  5L
  4956. #define TAPE_SPACE_FILEMARKS        6L
  4957. #define TAPE_SPACE_SEQUENTIAL_FMKS  7L
  4958. #define TAPE_SPACE_SETMARKS         8L
  4959. #define TAPE_SPACE_SEQUENTIAL_SMKS  9L
  4960.  
  4961. typedef struct _TAPE_SET_POSITION {
  4962.     DWORD Method;
  4963.     DWORD Partition;
  4964.     LARGE_INTEGER Offset;
  4965.     BOOLEAN Immediate;
  4966. } TAPE_SET_POSITION, *PTAPE_SET_POSITION;
  4967.  
  4968. //
  4969. // IOCTL_TAPE_GET_DRIVE_PARAMS definitions
  4970. //
  4971.  
  4972. //
  4973. // Definitions for FeaturesLow parameter
  4974. //
  4975.  
  4976. #define TAPE_DRIVE_FIXED            0x00000001
  4977. #define TAPE_DRIVE_SELECT           0x00000002
  4978. #define TAPE_DRIVE_INITIATOR        0x00000004
  4979.  
  4980. #define TAPE_DRIVE_ERASE_SHORT      0x00000010
  4981. #define TAPE_DRIVE_ERASE_LONG       0x00000020
  4982. #define TAPE_DRIVE_ERASE_BOP_ONLY   0x00000040
  4983. #define TAPE_DRIVE_ERASE_IMMEDIATE  0x00000080
  4984.  
  4985. #define TAPE_DRIVE_TAPE_CAPACITY    0x00000100
  4986. #define TAPE_DRIVE_TAPE_REMAINING   0x00000200
  4987. #define TAPE_DRIVE_FIXED_BLOCK      0x00000400
  4988. #define TAPE_DRIVE_VARIABLE_BLOCK   0x00000800
  4989.  
  4990. #define TAPE_DRIVE_WRITE_PROTECT    0x00001000
  4991. #define TAPE_DRIVE_EOT_WZ_SIZE      0x00002000
  4992.  
  4993. #define TAPE_DRIVE_ECC              0x00010000
  4994. #define TAPE_DRIVE_COMPRESSION      0x00020000
  4995. #define TAPE_DRIVE_PADDING          0x00040000
  4996. #define TAPE_DRIVE_REPORT_SMKS      0x00080000
  4997.  
  4998. #define TAPE_DRIVE_GET_ABSOLUTE_BLK 0x00100000
  4999. #define TAPE_DRIVE_GET_LOGICAL_BLK  0x00200000
  5000. #define TAPE_DRIVE_SET_EOT_WZ_SIZE  0x00400000
  5001.  
  5002. #define TAPE_DRIVE_EJECT_MEDIA      0x01000000
  5003.  
  5004. #define TAPE_DRIVE_RESERVED_BIT     0x80000000  //don't use this bit!
  5005. //                                              //can't be a low features bit!
  5006. //                                              //reserved; high features only
  5007.  
  5008. //
  5009. // Definitions for FeaturesHigh parameter
  5010. //
  5011.  
  5012. #define TAPE_DRIVE_LOAD_UNLOAD      0x80000001
  5013. #define TAPE_DRIVE_TENSION          0x80000002
  5014. #define TAPE_DRIVE_LOCK_UNLOCK      0x80000004
  5015. #define TAPE_DRIVE_REWIND_IMMEDIATE 0x80000008
  5016.  
  5017. #define TAPE_DRIVE_SET_BLOCK_SIZE   0x80000010
  5018. #define TAPE_DRIVE_LOAD_UNLD_IMMED  0x80000020
  5019. #define TAPE_DRIVE_TENSION_IMMED    0x80000040
  5020. #define TAPE_DRIVE_LOCK_UNLK_IMMED  0x80000080
  5021.  
  5022. #define TAPE_DRIVE_SET_ECC          0x80000100
  5023. #define TAPE_DRIVE_SET_COMPRESSION  0x80000200
  5024. #define TAPE_DRIVE_SET_PADDING      0x80000400
  5025. #define TAPE_DRIVE_SET_REPORT_SMKS  0x80000800
  5026.  
  5027. #define TAPE_DRIVE_ABSOLUTE_BLK     0x80001000
  5028. #define TAPE_DRIVE_ABS_BLK_IMMED    0x80002000
  5029. #define TAPE_DRIVE_LOGICAL_BLK      0x80004000
  5030. #define TAPE_DRIVE_LOG_BLK_IMMED    0x80008000
  5031.  
  5032. #define TAPE_DRIVE_END_OF_DATA      0x80010000
  5033. #define TAPE_DRIVE_RELATIVE_BLKS    0x80020000
  5034. #define TAPE_DRIVE_FILEMARKS        0x80040000
  5035. #define TAPE_DRIVE_SEQUENTIAL_FMKS  0x80080000
  5036.  
  5037. #define TAPE_DRIVE_SETMARKS         0x80100000
  5038. #define TAPE_DRIVE_SEQUENTIAL_SMKS  0x80200000
  5039. #define TAPE_DRIVE_REVERSE_POSITION 0x80400000
  5040. #define TAPE_DRIVE_SPACE_IMMEDIATE  0x80800000
  5041.  
  5042. #define TAPE_DRIVE_WRITE_SETMARKS   0x81000000
  5043. #define TAPE_DRIVE_WRITE_FILEMARKS  0x82000000
  5044. #define TAPE_DRIVE_WRITE_SHORT_FMKS 0x84000000
  5045. #define TAPE_DRIVE_WRITE_LONG_FMKS  0x88000000
  5046.  
  5047. #define TAPE_DRIVE_WRITE_MARK_IMMED 0x90000000
  5048. #define TAPE_DRIVE_FORMAT           0xA0000000
  5049. #define TAPE_DRIVE_FORMAT_IMMEDIATE 0xC0000000
  5050. #define TAPE_DRIVE_HIGH_FEATURES    0x80000000  //mask for high features flag
  5051.  
  5052. typedef struct _TAPE_GET_DRIVE_PARAMETERS {
  5053.     BOOLEAN ECC;
  5054.     BOOLEAN Compression;
  5055.     BOOLEAN DataPadding;
  5056.     BOOLEAN ReportSetmarks;
  5057.     DWORD DefaultBlockSize;
  5058.     DWORD MaximumBlockSize;
  5059.     DWORD MinimumBlockSize;
  5060.     DWORD MaximumPartitionCount;
  5061.     DWORD FeaturesLow;
  5062.     DWORD FeaturesHigh;
  5063.     DWORD EOTWarningZoneSize;
  5064. } TAPE_GET_DRIVE_PARAMETERS, *PTAPE_GET_DRIVE_PARAMETERS;
  5065.  
  5066. //
  5067. // IOCTL_TAPE_SET_DRIVE_PARAMETERS definitions
  5068. //
  5069.  
  5070. typedef struct _TAPE_SET_DRIVE_PARAMETERS {
  5071.     BOOLEAN ECC;
  5072.     BOOLEAN Compression;
  5073.     BOOLEAN DataPadding;
  5074.     BOOLEAN ReportSetmarks;
  5075.     DWORD EOTWarningZoneSize;
  5076. } TAPE_SET_DRIVE_PARAMETERS, *PTAPE_SET_DRIVE_PARAMETERS;
  5077.  
  5078. //
  5079. // IOCTL_TAPE_GET_MEDIA_PARAMETERS definitions
  5080. //
  5081.  
  5082. typedef struct _TAPE_GET_MEDIA_PARAMETERS {
  5083.     LARGE_INTEGER Capacity;
  5084.     LARGE_INTEGER Remaining;
  5085.     DWORD BlockSize;
  5086.     DWORD PartitionCount;
  5087.     BOOLEAN WriteProtected;
  5088. } TAPE_GET_MEDIA_PARAMETERS, *PTAPE_GET_MEDIA_PARAMETERS;
  5089.  
  5090. //
  5091. // IOCTL_TAPE_SET_MEDIA_PARAMETERS definitions
  5092. //
  5093.  
  5094. typedef struct _TAPE_SET_MEDIA_PARAMETERS {
  5095.     DWORD BlockSize;
  5096. } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
  5097.  
  5098. //
  5099. // IOCTL_TAPE_CREATE_PARTITION definitions
  5100. //
  5101.  
  5102. #define TAPE_FIXED_PARTITIONS       0L
  5103. #define TAPE_SELECT_PARTITIONS      1L
  5104. #define TAPE_INITIATOR_PARTITIONS   2L
  5105.  
  5106. typedef struct _TAPE_CREATE_PARTITION {
  5107.     DWORD Method;
  5108.     DWORD Count;
  5109.     DWORD Size;
  5110. } TAPE_CREATE_PARTITION, *PTAPE_CREATE_PARTITION;
  5111.  
  5112.  
  5113. #ifdef __cplusplus
  5114. }
  5115. #endif
  5116.  
  5117. #endif /* _WINNT_ */
  5118.  
  5119.